Skip to content

Instantly share code, notes, and snippets.

@MSeifert04
Last active July 17, 2017 12:38
Show Gist options
  • Save MSeifert04/e739bc60a703d4b9eca6849a80022006 to your computer and use it in GitHub Desktop.
Save MSeifert04/e739bc60a703d4b9eca6849a80022006 to your computer and use it in GitHub Desktop.
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