Skip to content

Instantly share code, notes, and snippets.

@akira093
Last active August 29, 2015 13:58
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 akira093/9981341 to your computer and use it in GitHub Desktop.
Save akira093/9981341 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#coding: utf-8
import timeit
test1 = """
import itertools
def test1():
count = itertools.count()
for i in count:
if i == 10000:
return
"""
test2 = """
def test2():
i = 0
while True:
if i == 10000:
return
i += 1
"""
if __name__ == '__main__':
print timeit.timeit("test1()", test1, number=5000)
# 1.53738689423
print timeit.timeit("test2()", test2, number=5000)
# 3.19617486
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment