Guest User

Untitled

a guest
Aug 4th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. $ cat >test.py
  2. import sys, timeit
  3.  
  4. def time_1():
  5. c = 0
  6. while 1:
  7. c += 1
  8. if c == 1000000: break
  9.  
  10. def time_true():
  11. c = 0
  12. while True:
  13. c += 1
  14. if c == 1000000: break
  15.  
  16. if __name__ == '__main__':
  17. count = int(sys.argv[1])
  18. print(' 1: %s') % timeit.timeit('time_1()', setup='from __main__ import time_1', number=count)
  19. print('True: %s') % timeit.timeit('time_true()', setup='from __main__ import time_true', number=count)
  20.  
  21. $ python2.7 bench.py 1
  22. 1: 0.0785179138184
  23. True: 0.113999128342
  24.  
  25. $ python2.7 bench.py 100
  26. 1: 6.82145810127
  27. True: 10.0693509579
  28.  
  29. $ python2.7 bench.py 1000
  30. 1: 63.2537529469
  31. True: 94.3908250332
Advertisement
Add Comment
Please, Sign In to add comment