Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ cat >test.py
- import sys, timeit
- def time_1():
- c = 0
- while 1:
- c += 1
- if c == 1000000: break
- def time_true():
- c = 0
- while True:
- c += 1
- if c == 1000000: break
- if __name__ == '__main__':
- count = int(sys.argv[1])
- print(' 1: %s') % timeit.timeit('time_1()', setup='from __main__ import time_1', number=count)
- print('True: %s') % timeit.timeit('time_true()', setup='from __main__ import time_true', number=count)
- $ python2.7 bench.py 1
- 1: 0.0785179138184
- True: 0.113999128342
- $ python2.7 bench.py 100
- 1: 6.82145810127
- True: 10.0693509579
- $ python2.7 bench.py 1000
- 1: 63.2537529469
- True: 94.3908250332
Advertisement
Add Comment
Please, Sign In to add comment