Skip to content

Instantly share code, notes, and snippets.

Created October 15, 2010 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/627687 to your computer and use it in GitHub Desktop.
Save anonymous/627687 to your computer and use it in GitHub Desktop.
Time Test
def tryway():
try:
while True:
alist.pop()
except IndexError:
pass
def ifway():
while True:
if blist == []:
break
else:
blist.pop()
if __name__=='__main__':
alist = range(1000)
blist = range(1000)
from timeit import Timer
print "Testing Try"
tr = Timer("tryway()","from __main__ import tryway")
print tr.timeit()
print "Testing If"
ir = Timer("ifway()","from __main__ import ifway")
print ir.timeit()
Results
Testing Try
2.87330579758
Testing If
0.314908027649
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment