Created
March 23, 2021 11:33
-
-
Save kristjan-eljand/2e71f1be47483e64a0e6c722ea1d1f69 to your computer and use it in GitHub Desktop.
Counter per scond
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 | |
# 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