Created
December 16, 2021 01:06
-
-
Save tateg/f0faea4a8d92748983ba0ff257160163 to your computer and use it in GitHub Desktop.
Basic Python loop timing with print statements in the loop
This file contains hidden or 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
from time import time_ns | |
before_ts = time_ns() | |
for num in range(0, 1000): | |
print(num) | |
after_ts = time_ns() | |
diff = after_ts - before_ts | |
print('loop time in \n' \ | |
'nanoseconds: ' + str(diff) + '\n' + \ | |
'microseconds: ' + str(diff / 1000) + '\n' + \ | |
'milliseconds: ' + str((diff / 1000) / 1000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment