Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # global_vs_local_timeit.py
- from timeit import default_timer as timer
- N = 100000
- test = {'G min': 99, 'L min': 99, 'G max': 0, 'L max': 0}
- def f():
- for i in range(N):
- pass
- for z in range(10):
- start = timer()
- for i in range(N):
- pass
- a = timer() - start
- print("global %.5f" % a)
- start = timer()
- f()
- b = timer() - start
- print("function %.5f" % b)
- print
- test['G min'] = min(test['G min'], a)
- test['L min'] = min(test['L min'], b)
- test['G max'] = max(test['G max'], a)
- test['L max'] = max(test['L max'], b)
- zzz = 'G min/L min/G max/L max'.split('/')
- for z in zzz:
- print z, test[z]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement