Created
September 29, 2021 17:19
-
-
Save mikeckennedy/f516c9cf2f7a69a02a815e3799b42f95 to your computer and use it in GitHub Desktop.
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 datetime | |
def run_with_no_ex(count: int): | |
idx = 0 | |
while idx < count: | |
idx += 1 | |
s = "".upper() | |
def run_with_ex(count: int): | |
idx = 0 | |
while idx < count: | |
idx += 1 | |
try: | |
s = "".upper() | |
except Exception as x: | |
print(f"Error! {x}") | |
def time(func, count, msg): | |
t0 = datetime.datetime.now() | |
func(count) | |
dt = datetime.datetime.now() - t0 | |
print(f'Finished {msg} in {dt.total_seconds()*1000:,.0f}ms') | |
if __name__ == '__main__': | |
run_with_ex(1) | |
run_with_no_ex(1) | |
time(run_with_no_ex, 1_000_000*100, "No exception block") | |
time(run_with_ex, 1_000_000*100, "Exception block") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output seems pretty much tied for me: