Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # array_timeit.py
- from array import *
- import timeit
- test = {'direct min': 99, 'arrays min': 99, 'direct max': 0, 'arrays max': 0}
- def f1():
- global t
- t += 1
- def f2():
- p[0] += 1
- # f1
- t = 0
- # f2
- p = array('i', [0])
- for z in range(10):
- a = timeit.timeit("f1()", setup="from __main__ import f1")
- b = timeit.timeit("f2()", setup="from __main__ import f2")
- print 'direct =', a
- print 'arrays =', b
- print
- test['direct min'] = min(test['direct min'], a)
- test['arrays min'] = min(test['arrays min'], b)
- test['direct max'] = max(test['direct max'], a)
- test['arrays max'] = max(test['arrays max'], b)
- zzz = 'direct min/arrays min/direct max/arrays max'.split('/')
- for z in zzz:
- print z, test[z]
- print
- print(t)
- print(p[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement