Advertisement
here2share

# global_vs_local_timeit.py

Nov 28th, 2019
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. # global_vs_local_timeit.py
  2.  
  3. from timeit import default_timer as timer
  4.  
  5. N = 100000
  6.  
  7. test = {'G min': 99, 'L min': 99, 'G max': 0, 'L max': 0}
  8.  
  9. def f():
  10.     for i in range(N):
  11.         pass
  12.  
  13. for z in range(10):
  14.     start = timer()
  15.     for i in range(N):
  16.         pass
  17.     a = timer() - start
  18.     print("global   %.5f" % a)
  19.  
  20.     start = timer()
  21.     f()
  22.     b = timer() - start
  23.     print("function %.5f" % b)
  24.     print
  25.    
  26.     test['G min'] = min(test['G min'], a)
  27.     test['L min'] = min(test['L min'], b)
  28.     test['G max'] = max(test['G max'], a)
  29.     test['L max'] = max(test['L max'], b)
  30.  
  31. zzz = 'G min/L min/G max/L max'.split('/')
  32. for z in zzz:
  33.     print z, test[z]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement