Skip to content

Instantly share code, notes, and snippets.

@muayyad-alsadi
Created July 5, 2014 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muayyad-alsadi/8c8a8fc6bf698fff8517 to your computer and use it in GitHub Desktop.
Save muayyad-alsadi/8c8a8fc6bf698fff8517 to your computer and use it in GitHub Desktop.
do not benchmark yield
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): f(*a, **kw)
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