Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import time
- def timeWrap(func):
- def wrapper(*args, **kwargs):
- t0 = time.time()
- result = func(*args, **kwargs)
- print "It took:", time.time() - t0, "seconds"
- return result
- return wrapper
- @timeWrap
- def xstr():
- for i in range(10000):
- s = ''
- for j in range(10):
- s += str(j)
- @timeWrap
- def xlist():
- for i in range(10000):
- s = [0,0,0,0,0,0,0,0,0,0]
- for j in range(10):
- s[j] = j
- @timeWrap
- def xarray():
- for i in range(10000):
- s = np.ndarray((10,))
- for j in range(10):
- s[j] = j
- @timeWrap
- def xdict():
- for i in range(10000):
- s = {}
- for j in range(10):
- s[j] = j
- print 'str',
- xstr()
- print 'list',
- xlist()
- print 'array',
- xarray()
- print 'dict',
- xdict()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement