Created
July 5, 2014 14:50
-
-
Save muayyad-alsadi/dde1f80eeb52a2f6cd5f to your computer and use it in GitHub Desktop.
primes in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def get_primes(n): | |
compo=set() | |
for i in xrange(2, n): | |
if i in compo: continue | |
yield i | |
compo.update(xrange(i*2, n,i)) | |
def benchmark(f, n): | |
def wrapped(*a, **kw): | |
t0=time.time() | |
for i in xrange(n): | |
for p in f(*a, **kw): pass | |
print "dt=", time.time()-t0 | |
return wrapped | |
benchmark(get_primes, 500)(10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment