Created
October 15, 2010 05:36
-
-
Save anonymous/627687 to your computer and use it in GitHub Desktop.
Time Test
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
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