Mine værktøjer
Du er her: Forside Python program eksempler. Performance

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 )


« august 2018 »
søn man tir ons tor fre lør
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Chat Rooms
Dyrk motion

Trim ballerup

 

Powered by Plone, the Open Source Content Management System