Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def tryway():
- alist = list(range(1000))
- try:
- while True:
- alist.pop()
- except IndexError:
- pass
- def ifway():
- alist = list(range(1000))
- while True:
- if alist == []:
- break
- else:
- alist.pop()
- if __name__=='__main__':
- from timeit import Timer
- print("Testing Try")
- tr = Timer("tryway()","from __main__ import tryway")
- print(tr.timeit(10000))
- print("Testing If")
- ir = Timer("ifway()","from __main__ import ifway")
- print(ir.timeit(10000))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement