Legendre prime counting function: Difference between revisions

m
add some compiler optimizations
m (add some compiler optimizations)
Line 2,069:
cmpsts = falses(mxndx + 1)
bp, npc, mxri = 3, 0, mxndx
@inbounds while true
i = bp >> 1
sqri = (i + i) * (i + 1)
Line 2,091:
end
m = mxndx
@simd for k in (rtlmt ÷ bp - 1) | 1 : -2 : bp
c = smalls[k >> 1 + 1] - npc
ee = (k * bp) >> 1
Line 2,106:
 
result = larges[1]
@simd for i in 2:mxri+1
result -= larges[i]
end
Line 2,128:
end
 
@time countprimes(10^13)
@time countprimes(10^14)
 
</syntaxhighlight>{{out}}
<pre>
Line 2,147:
π(10^13) = 346065536839
π(10^14) = 3204941750802
40.744442894891 seconds (13 allocations: 15348.185442 MiB, 01.1606% gc time)
4.479385 seconds (13 allocations: 153.185 MiB, 0.12% gc time)
</pre>
 
4,105

edits