for
loops with np.arange
seem to be quicker than manual while
loops for certain powers of 10. The inverse is true for some other numbers and interestingly, 10 million loops. I got this pattern fairly consistently with
- Python 3.6.9
- Linux Mint 19.3 (Linux g-X551CA 5.3.0-46-generic #38~18.04.1-Ubuntu SMP Tue Mar 31 04:17:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux)
- Intel(R) Core(TM) i3-3217U CPU @ 1.80GHz
- Numpy 1.18.2
The benchmark function is a dice roller that rolls a positive number of dice each with a positive number of sides 2+ times a batch, and calculates means for each batch. It does this by allocating nBatch * nRolls random integers between 1 and nSides * nDice (inclusive), so the run time of the function is probably consistent between runs.