Skip to content

Instantly share code, notes, and snippets.

@borntyping
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borntyping/9388000 to your computer and use it in GitHub Desktop.
Save borntyping/9388000 to your computer and use it in GitHub Desktop.
❯ python2 ~/dev/while.py
3.16730904579
2.61067199707
❯ python3 ~/dev/while.py
4.79477457899975
2.070868385999802
from __future__ import print_function
import timeit
def counter(limit):
i = 0
while i < limit:
i += 1
pass
def generator(limit):
for i in range(limit):
pass
print(timeit.timeit('counter(1000000)', setup='from __main__ import counter', number=100))
print(timeit.timeit('generator(1000000)', setup='from __main__ import generator', number=100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment