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

Untitled

By: a guest on Feb 28th, 2013  |  syntax: Python  |  size: 0.45 KB  |  views: 41  |  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. def is_prime(n):
  4.     for i in range(2, int(n**0.5)+1):
  5.         if n%i == 0:
  6.             return False
  7.     return True
  8.  
  9. times = []
  10.  
  11. for i in range(50):
  12.     num = 0
  13.     primes_found = 0
  14.     begin_time = time.time()
  15.  
  16.     while primes_found != 10000:
  17.         if is_prime(num):
  18.             primes_found += 1
  19.         num += 1
  20.  
  21.     times.append(time.time() - begin_time)
  22.  
  23. print "Average Time: {:f}ms".format((sum(times)/len(times))*1000)