Created
May 30, 2019 18:08
-
-
Save StuartFarmer/d425ea187f49247851a74cb6d2beda71 to your computer and use it in GitHub Desktop.
Timeit Try Except Finally
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 timeit | |
te = ''' | |
try: | |
pass | |
except: | |
pass | |
''' | |
tf = ''' | |
try: | |
pass | |
finally: | |
pass | |
''' | |
tef = ''' | |
try: | |
pass | |
except: | |
pass | |
finally: | |
pass | |
''' | |
te_time = timeit.timeit(te) | |
tf_time = timeit.timeit(tf) | |
tef_time = timeit.timeit(tef) | |
print('Try/Except Setup Time: {}'.format(te_time)) | |
print('Try/Finally Setup Time: {}'.format(tf_time)) | |
print('Try/Except/Finally Setup Time: {}'.format(tef_time)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment