performance.py
by
admin
—
last modified
2008-02-12 23:23
demonstrerer performance af psyco. Ved at installere psyco kan beregninger forbedres med en faktor 10.
Size 1 kB - File type text/python-sourceFile contents
#!/user/env python
#
#html# Licence <a href="/bauerdata/diverse-filer-til-download-mm/gpl.txt/view">GPL</a>
#
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 )
Click here to get the file