SHARE
TWEET

Untitled

a guest Feb 28th, 2013 42 Never
  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)
RAW Paste Data
Top