Created
April 20, 2017 18:56
-
-
Save nasturtus/751b58811ed7f90dd20aeefb99db0b17 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
# Illustrate timeit to time code snippets. | |
import timeit | |
# timeit should be callable and requires two arguments: | |
# a string and number of iterations. | |
# A basic timeit | |
print(timeit.timeit('10 + 2', number=1000000)) | |
# timeit for generator | |
print(timeit.timeit('''gen = (i for i in range(100))''', number=1000000)) | |
# timeit for list comprehension | |
print(timeit.timeit('''lst = [i for i in range(100)]''', number=1000000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment