Skip to content

Instantly share code, notes, and snippets.

@kristjan-eljand
Last active March 17, 2021 11:58
Show Gist options
  • Save kristjan-eljand/5ddc1f58ef398f880aa43cba21f3248e to your computer and use it in GitHub Desktop.
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
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