4 ms·
lol none of the loops do any work after the first time. Hence why they run 200,000,000 times (this would be 10 trillion additions/second if the loops were actua
by cia_plant 13y ago
lol none of the loops do any work after the first time. Hence why they run 200,000,000 times (this would be 10 trillion additions/second if the loops were actually running). Epic fail.
- hamburglar 13y agoIt took me a while to understand what you meant by this. It was obvious to me that the loops under test do do work (the shift/increment) every time through. But we're talking about different loops. For others trying to understand this comment: the TEST loop which runs the code being benchmarked is short-circuited in the 'do' and 'while' cases because the setup code does not get re-run, so on the first test loop, it sums up an array of random numbers, and on subsequent runs, it sums an empty array. This also gave me the 'aha' that explained why the huge difference between 'while' and 'do': in the 'do' case, we execute the loop at least once in every one of the hundreds of millions of test runs, whereas in the 'while' case, the loop is executed 0 times in all but one run.