Skip to content

Instantly share code, notes, and snippets.

@StuartFarmer
Created May 30, 2019 18:08
Show Gist options
  • Save StuartFarmer/d425ea187f49247851a74cb6d2beda71 to your computer and use it in GitHub Desktop.
Save StuartFarmer/d425ea187f49247851a74cb6d2beda71 to your computer and use it in GitHub Desktop.
Timeit Try Except Finally
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