fork download
  1. # your code goes here
  2.  
  3.  
  4. import time
  5.  
  6. xs = range(10)
  7.  
  8. start = time.time()
  9.  
  10. c = 0
  11. for i in xrange(0,100000):
  12. for x in xs:
  13. c += x
  14.  
  15. elapsed_time = time.time() - start
  16.  
  17. print "normal =%d %s" % (c,elapsed_time)
  18.  
  19. xs.append("hage") #add delimiter
  20.  
  21. start = time.time()
  22.  
  23. c = 0
  24. for i in xrange(0,100000):
  25. for x in xs:
  26. if isinstance(x,int):
  27. c += x
  28.  
  29. elapsed_time = time.time() - start
  30.  
  31. print "typechecked =%d %s" % (c,elapsed_time)
  32.  
  33. start = time.time()
  34. c = 0
  35. for i in xrange(0,100000):
  36. try:
  37. for x in xs:
  38. c += x
  39. except:
  40. pass
  41.  
  42. elapsed_time = time.time() - start
  43.  
  44. print "except =%d %s" % (c,elapsed_time)
  45.  
  46.  
  47.  
Success #stdin #stdout 1.34s 7856KB
stdin
Standard input is empty
stdout
normal =4500000 0.238799095154
typechecked =4500000 0.650162220001
except =4500000 0.439296007156