Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Paul McGuire

By: a guest on Sep 19th, 2009  |  syntax: Python  |  size: 0.57 KB  |  views: 102  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import time
  2.  
  3. time.clock()
  4.  
  5. for numelements in (1000,10000,100000,1000000):
  6.     print numelements
  7.     L = range(numelements)
  8.  
  9.     start = time.clock()
  10.  
  11.     I = set()
  12.     for i in range(len(L)):
  13.         # if not L[i].isValid():
  14.         if i % 11 == 0:
  15.             I.add(i)
  16.            
  17.     for i in sorted(I, reverse=True):
  18.         del L[i]
  19.  
  20.     end = time.clock()
  21.     print end-start
  22.  
  23.     L = range(numelements)
  24.  
  25.     start = time.clock()
  26.  
  27.     L = [ item for i,item in enumerate(L) if i % 11 != 0 ]
  28.  
  29.     end = time.clock()
  30.     print end-start
  31.     print