Skip to content

Instantly share code, notes, and snippets.

@kristjan-eljand
Created March 23, 2021 11:33
Show Gist options
  • Save kristjan-eljand/2e71f1be47483e64a0e6c722ea1d1f69 to your computer and use it in GitHub Desktop.
Save kristjan-eljand/2e71f1be47483e64a0e6c722ea1d1f69 to your computer and use it in GitHub Desktop.
Counter per scond
import time
# Function that runs the counter for 1 second
def count_per_second(x):
start = time.time()
counter = 0
while time.time() - start < 1:
counter += 1
return counter
start = time.time()
# Execute the function 9 times
results = [count_per_second(x) for x in range(9)]
print("duration =", time.time() - start)
print("results =", results)
# Output:
# duration = 9.000171661376953
# results = [792793, 818272, 791557, 808990, 818746, 815934, 815764, 814871, 799357]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment