Prime decomposition: Difference between revisions

→‎{{header|Python}}: performance hints
(minor correction to Clojure version)
(→‎{{header|Python}}: performance hints)
Line 910:
</pre>
Note: Python took 740,238 BogoMI to complete the example.
 
Modifying the primes() and is_prime() functions as below increases performance.
<lang python>def is_prime(n):
return all( y==n for y in decompose(n))
primelist = [2,3]
max_tested = 3
def primes():
global max_tested
for n in primelist:
yield n
n = max_tested
pmax = sys.maxint-2
while n < pmax:
n += 2
while not is_prime(n) and n < pmax:
n += 2
if n < pmax:
primelist.append(n)
max_tested = n
yield n</lang>
 
=={{header|R}}==
Anonymous user