Performance
Tilbage
Hent filen
Licens GPL
demonstrerer performance af psyco. Ved at installere psyco kan beregninger forbedres med en faktor 10.
#!/user/env python
#
# Licence GPL
#
import time
def performance(N = 1000000000 ):
i, sum = 0, 0
t1 = time.time()
while i < N :
sum = ((sum + 1) * 2 + 1) / 2
i += 1
t2 = time.time()
if sum != N:
print "error"
else:
print "python: %d operations in %d seconds" % (N, t2 - t1)
if __name__ == "__main__":
import sys
N = 100000000
print "first run without optimize"
performance( N=N )
try:
import psyco
psyco.full()
except:
print "psyco not found"
sys.exit(1)
print "then run with optimize"
performance( N=N )