Created
June 30, 2011 19:44
-
-
Save sugar84/1057039 to your computer and use it in GitHub Desktop.
python test measurement
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
#!/usr/bin/env python | |
def get_primes7(n): | |
if n < 2: return [] | |
if n == 2: return [2] | |
# do only odd numbers starting at 3 | |
s = [] | |
for t in range(1, n/2): | |
s.append(t*2 + 1) | |
# n**0.5 simpler than math.sqr(n) | |
mroot = n ** 0.5 | |
half = len(s) | |
i = 0 | |
m = 3 | |
while m <= mroot: | |
if s[i]: | |
j = (m*m-3)//2 # int div | |
s[j] = 0 | |
while j < half: | |
s[j] = 0 | |
j += m | |
i = i+1 | |
m = 2*i+3 | |
return [2]+[x for x in s if x] | |
for t in range(10): | |
res = get_primes7(10000000) | |
print "Found", len(res), "prime numbers." | |
""" | |
__END__ | |
$ /usr/bin/time ./math_test.py | |
Found 664579 prime numbers. | |
Found 664579 prime numbers. | |
Found 664579 prime numbers. | |
Found 664579 prime numbers. | |
Found 664579 prime numbers. | |
Found 664579 prime numbers. | |
Found 664579 prime numbers. | |
Found 664579 prime numbers. | |
Found 664579 prime numbers. | |
Found 664579 prime numbers. | |
46.34user 0.38system 0:46.73elapsed 99%CPU |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment