Advertisement
cmaureir

Untitled

Jul 20th, 2021
1,695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. def tryway():
  2.     alist = list(range(1000))
  3.     try:
  4.         while True:
  5.             alist.pop()
  6.     except IndexError:
  7.         pass
  8.  
  9. def ifway():
  10.     alist = list(range(1000))
  11.     while True:
  12.         if alist == []:
  13.             break
  14.         else:
  15.             alist.pop()
  16. if __name__=='__main__':
  17.     from timeit import Timer
  18.     print("Testing Try")
  19.     tr = Timer("tryway()","from __main__ import tryway")
  20.     print(tr.timeit(10000))
  21.     print("Testing If")
  22.     ir = Timer("ifway()","from __main__ import ifway")
  23.     print(ir.timeit(10000))
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement