Last active
March 17, 2021 11:58
-
-
Save kristjan-eljand/5ddc1f58ef398f880aa43cba21f3248e to your computer and use it in GitHub Desktop.
Sleeper function that sleeps for 1 sec and then returns its argument
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 time #to measure the execution time | |
def sleeper_function(x): | |
time.sleep(1) | |
return x | |
# Execute the function 4 times and measure the execution time | |
start = time.time() | |
results = [sleeper_function(x) for x in range(4)] | |
print("duration =", time.time() - start) | |
print("results =", results) | |
# duration = 4.004324674606323 | |
# results = [0, 1, 2, 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment