Last active
July 17, 2017 12:38
-
-
Save MSeifert04/e739bc60a703d4b9eca6849a80022006 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
import timeit | |
def f_range(n): | |
for i in range(n): | |
pass | |
def f_xrange(n): | |
for i in xrange(n): | |
pass | |
def f_while(n): | |
i = 0 | |
while i < 100: | |
i += 1 | |
print(timeit.timeit("f_range(100)", "from __main__ import f_range")) # 7.39035423582 | |
print(timeit.timeit("f_xrange(100)", "from __main__ import f_xrange")) # 5.14161613217 | |
print(timeit.timeit("f_while(100)", "from __main__ import f_while")) # 13.3456207994 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment