Problem with timeit
ast
nomail at com.invalid
Fri Dec 15 05:36:19 EST 2017
Hi
Time measurment with module timeit seems to work with some
statements but not with some other statements on my computer.
Python version 3.6.3
from timeit import Timer
>>> Timer("'-'.join([str(i) for i in range(10)])").timeit(10000)
0.179271876732912
>>> Timer("'-'.join([str(i) for i in range(10)])").timeit(100000)
1.7445643231192776
It's OK, with 10 more loops I get 10 more execution time.
But with exponentiation, it's a mess
>>> Timer("x=123456**123456").timeit(1)
6.076191311876755e-06
>>> Timer("x=123456**123456").timeit(10)
3.841270313387213e-06
All wrong, the calculation of 123456**123456 is much longer
than 6 microseconds, it takes few seconds, and with 10 loops
timeit provided a shorter time ...
What happens plz ?
More information about the Python-list
mailing list