Skip to content

Instantly share code, notes, and snippets.

@zed
Created July 28, 2012 13:41
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 zed/dc8be82c7b4c4d4ac0de to your computer and use it in GitHub Desktop.
Save zed/dc8be82c7b4c4d4ac0de to your computer and use it in GitHub Desktop.
Typed version of Python code for the (for-loop,modulo) benchmark
"""Benchmark http://stackoverflow.com/questions/11641098/interpreting-a-benchmark-in-c-clojure-python-ruby-scala-and-others#comment15487214_11641098
"""
import cython
@cython.locals(n=int,j=int)
def is_prime(n):
for j in xrange(2, n):
if n % j == 0:
return False
return True
def primes_below(x):
return [(j-6, j) for j in xrange(9, x + 1) if is_prime(j) and is_prime(j-6)]
def main(argv):
n = int(argv[1]) if len(argv) > 1 else 100*1000
print(primes_below(n))
if __name__=="__main__":
import sys
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment