Created
September 1, 2020 06:40
-
-
Save Kush1101/4bfe14883f32bc59899d8e4aa511083d to your computer and use it in GitHub Desktop.
Medium_timeit
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 | |
#This code will be executed only once, before stmt. | |
setup_code = "from math import sqrt" | |
#This code will be executed as specified by the parameter 'number' | |
stmt_code = "sum(sqrt(x) for x in range(1,10000))" | |
iterations = 10000 | |
time = timeit.timeit(stmt = stmt_code, setup = setup_code, number = iterations) | |
print(time) | |
#17.9 seconds | |
#THIS OUTPUT IS FOR 10000 ITERATIONS OF THE CODE SNIPPET AND NOT A SINGLE ITERATION. | |
print(f"The time for single iteration is {time/iterations}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment