excel - Surprising nested loops duration -


I have an internal and external loop in my VBA code. I think execution time in total external loop count * Internal loop It can be estimated as a number, but it does not seem that 10 * 10 ^ 8 functions take approximately 5 seconds during the performance, but 10 ^ 8 * 10 takes about 24 seconds for operation. Multiple iterations of the outer loop, compared to many iterations of these loops Not to make the total execution time, although the total number of operations is the same in both instances. Should that work? Why is it like this? Am I doing something wrong?

  Sub-testing () long as long as Jammu Eye as a single maxI = 0 '1 maxJ = 9' 1 billion while maxJ & gt; = 0 for t = timer i = 1 to 10 ^ maxI for j = 1 to 10 ^ maxJ next h next i debug. Print max + max J & amp; "" & Amp; Maxi & amp; "" & Amp; Max J & amp; "" & Amp; Timer - T Maxi = Maxi + 1 Maxje = MaxJay - 1 loop and sub   

Dinosatic resumance with the quadratic iterations in the outer loop and a recurrence in the interior looks like this: / P>

  + ------------------- + ----------------- + - - -------------- + ---------- + | Total_operation | Outer_loop_cnt | Inner_loop_cnt | Time | + ------------------- + ----------------- + ----------- ------ + ---------- + | 9 | 9 | 0 | 222,2305 | | 9 | 8 | 1 | 24,52734 | | 9 | 7 | 2 | 8,300781 | | 9 | 6 | 3 | 5,6835 9 4. | 9 | 5 | 4 | 5,070313 | | 9 | 4 | 5 | 5,10 9 375 | 9 | 3 | 6 | 5,1679 9 6. 9 | 2 | 7 | 4,93,359 4. | 9 | 1 | 8 | 4,8 9 4,388 | 9 | 0 | 9 | 5,10 9 375 + ------------------- + ----------------- + ----------- ------ + ---------- +   

The resulting dataset, which starts with quadratic iterations in the inner loop and a repetition in the outer one, looks like this Is:

  + --- --- --- --- + ---------- + | 9 | 0 | 9 | 4,800781 | | 9 | 1 | 8 | 4,8 9 625 | 9 | 2 | 7 | 4,80,854. | 9 | 3 | 6 | 4,800781 | | 9 | 4 | 5 | 4,757813 | | 9 | 5 | 4 | 4972656 | | 9 | 6 | 3 | 5,3085 9 4. | 9 | 7 | 2 | 6,980,469 | 9 | 8 | 1 | 24,54,297. | 9 | 9 | 0 | 222,3828 | Update: If I change the code, then upper There are no limitations in this way each loop is counted as:  
  Maximum J & gt = 0 upper _i = 10 ^ maximum upper_z = 10 ^ max jt = timer i = 1 for upper_i Upper_z for j = 1 ..   

I get better results for larger outer loops. But it is still true, to achieve the best performance, internal and external loop Almost bar Cabar seems best to calculate. For me, it's still surprising, any thoughts?

  90 607070 9 8 1 14,812 9 2 2 10, 36719 93939, 41, 4639549, 50781339559, 4062593969 , 523438 9 72 7, 835 9 381, 81287591111234499759198, 257813797, 266 625 9 369, 2734389.549, 1875595 49, 164063 9 6, 9, 21875 9 7 2 10, 49 69 69 8 1 14, 9 60 9 9 59 59 666 6 How can I do table formatting, BTW? ?  

Yes, it makes sense to loop limit always calculated at the beginning of the loop So if you run the internal loop one billion times, then you are computing one time, 10 ^ maxI , then 10 ^ maxJ once again j = j + 1 If you run an external loop one billion times, then you are doing 10 ^ maxI , and 10 ^ maxJ and j = j + 1 one billion times.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -