Also inspired by https://gist.github.com/havenwood/4724778. Sexy-prime ruby script can be found there.
import time;
def is_prime(n):
return all(n%i!=0 for i in range(2,n));
def sexy_primes(n):
return filter(lambda x: all(is_prime(y) for y in x),[(i-6,i) for i in range(9,n)]);
a = time.time();
sexy_primes(100000);
b = time.time();
print(b - a);
Note: Following time is result on rubbish machine, so result may varies.
- Topaz (trunk): 19.18 sec
- PyPy (1.9): 24.44 sec
- Python (2.7.3): 308.45 sec
- MRI-Ruby (1.9.3-p327): 309.95 sec
Another unscientific benchmark can be found at: https://gist.github.com/lpm11/4945388