Last active
August 29, 2015 13:58
-
-
Save akira093/9981341 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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