Skip to content

@abbot /gist:954809
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
function call timings
import time
def f(x):
return x + 1
def z(x):
pass
def g(x):
z(x)
return x + 1
# uncomment these 2 lines for psyco
#import psyco
#psyco.full()
N = 20000000
start1 = time.time()
i=0
while i < N:
i = f(i)
end1 = time.time()
delta1 = end1-start1
start2 = time.time()
i=0
while i < N:
i = g(i)
end2 = time.time()
delta2 = end2-start2
print delta1, delta2, (delta2-delta1)*1e9/N, "ns/call", N/(delta2-delta1), "calls/sec"
# typcal run times on Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz
# Python 2.4.6, 64bit, no psyco
# 6.19973611832 9.58061480522 169.043934345 ns/call 5915621.89956 calls/sec
# Python 2.6.6, 32bit, no psyco
# 5.94791007042 9.30321216583 167.765104771 ns/call 5960715.14018 calls/sec
# Python 2.7, 64bit, no psyco
# 5.8356180191 9.63286614418 189.862406254 ns/call 5266972.11803 calls/sec
#
# Now with psyco, numbers fluctuate from run to run
# Python 2.6.6, 32bit, with psyco, 5 consecutive runs
# 11.0202350616 11.1978240013 8.87944698334 ns/call 112619626.186 calls/sec
# 11.818434 12.3235349655 25.255048275 ns/call 39596043.8923 calls/sec
# 12.888532877 13.0846998692 9.80834960938 ns/call 101953951.462 calls/sec
# 11.3699889183 11.9367079735 28.3359527588 ns/call 35290854.9966 calls/sec
# 11.6484761238 12.336867094 34.4195485115 ns/call 29053257.3275 calls/sec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.