-
-
Save zed/dc8be82c7b4c4d4ac0de to your computer and use it in GitHub Desktop.
Typed version of Python code for the (for-loop,modulo) benchmark
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
"""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