Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- ##from time import clock
- if sys.version_info.major == 2:
- from time import clock
- else:
- from time import monotonic as clock
- def profiler(func):
- def wrapper(*args, **kwargs):
- t = clock()
- r = func(*args, **kwargs)
- print('{} iterations completed for {} milliseconds'.format(args[0], round(clock() - t, 4) * 1000))
- return r
- return wrapper
- @profiler
- def main(s):
- c = 0
- for i in range(s):
- c+=1
- return c
- if __name__ == '__main__':
- for i in range(5):
- main(10**6)
- # => around 70ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement