Legendre prime counting function: Difference between revisions

Content added Content deleted
m (add some compiler optimizations)
Line 2,069: Line 2,069:
cmpsts = falses(mxndx + 1)
cmpsts = falses(mxndx + 1)
bp, npc, mxri = 3, 0, mxndx
bp, npc, mxri = 3, 0, mxndx
while true
@inbounds while true
i = bp >> 1
i = bp >> 1
sqri = (i + i) * (i + 1)
sqri = (i + i) * (i + 1)
Line 2,091: Line 2,091:
end
end
m = mxndx
m = mxndx
for k in (rtlmt ÷ bp - 1) | 1 : -2 : bp
@simd for k in (rtlmt ÷ bp - 1) | 1 : -2 : bp
c = smalls[k >> 1 + 1] - npc
c = smalls[k >> 1 + 1] - npc
ee = (k * bp) >> 1
ee = (k * bp) >> 1
Line 2,106: Line 2,106:


result = larges[1]
result = larges[1]
for i in 2:mxri+1
@simd for i in 2:mxri+1
result -= larges[i]
result -= larges[i]
end
end
Line 2,128: Line 2,128:
end
end


@time countprimes(10^13)
@time countprimes(10^14)
@time countprimes(10^14)

</syntaxhighlight>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
Line 2,147: Line 2,147:
π(10^13) = 346065536839
π(10^13) = 346065536839
π(10^14) = 3204941750802
π(10^14) = 3204941750802
4.744442 seconds (13 allocations: 153.185 MiB, 0.16% gc time)
0.894891 seconds (13 allocations: 48.442 MiB, 1.06% gc time)
4.479385 seconds (13 allocations: 153.185 MiB, 0.12% gc time)
</pre>
</pre>