D
Dennis Benzinger
I just played around with the new timeit module.
Using the following code I get some strange results:
import timeit
def test(s):
result = 0
for c in s:
result += ord(c)
return result
t = timeit.Timer("test('dennisbenzinger')", "from __main__ import test")
print t.repeat(number=50000)
Most of the time I get a result like
But sometimes I get something like
ones, although the program took about the same time to execute
and certainly not some thousand times as long...
I'm running Python 2.3.2 on Windows 2000 with ServicePack 4
Using the following code I get some strange results:
import timeit
def test(s):
result = 0
for c in s:
result += ord(c)
return result
t = timeit.Timer("test('dennisbenzinger')", "from __main__ import test")
print t.repeat(number=50000)
Most of the time I get a result like
with all execution times are about 3.>> [3.3263199652469799, 3.3338471789012294, 3.3557058229467716]
But sometimes I get something like
where one or two execution times are much higher than the other>> [3.3410785448988629, 4802.7882074397721, 1203.1983464378854]
ones, although the program took about the same time to execute
and certainly not some thousand times as long...
I'm running Python 2.3.2 on Windows 2000 with ServicePack 4