Ilya Zakharevich on Fri, 16 Aug 2024 02:04:38 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: 2.16.2-beta: 2.45× slowdown in forprime()


On Thu, Aug 15, 2024 at 04:45:42PM -0700, Ilya Zakharevich wrote:
> Comparing to the older versions, forprime() is perfectly OK at least
> until 10^17.  However, for 10^18 it slows down 2.45× times:


> With older PARIs, the speed decreases to about 2*10^17, then practically
> stabilizes at about 8.8 sec per 10^8 numbers.  Contrary to this, With
> newer PARIs, it slows down uniformly in the interval 10^17 .. 10^18:
> 
>   (16:35) gp > timeit(s,f) = my(t=gettime(), o=f()); if(#o, o=Str("\t",o)); printf("%s%7.3f%s\n",s,gettime()/1000,o);

In fact, the situation is yet more interesting.  With older PARI, the
speed decreases to about 1.9e17, then SPEEDS UP abruptly, and keeps
approximately constant:

  (16:51) gp > my(D=15, c, L=10^8); forstep(k=185,200,1, c=0; timeit(Strprintf("%d*10^%d\t",k, D),  (()->forprime(p=k*10^D,k*10^D+L,c++);c)))
  185*10^15         9.985 2514431
  186*10^15        10.001 2514008
  187*10^15        10.025 2514607
  188*10^15        10.054 2513151
  189*10^15        10.081 2513754
  190*10^15        10.095 2511725
  191*10^15         8.722 2512296
  192*10^15         8.756 2513602
  193*10^15         8.736 2512715
  194*10^15         8.687 2510748
  195*10^15         8.708 2512232
  196*10^15         8.576 2513044
  197*10^15         8.694 2512444
  198*10^15         8.923 2512685
  199*10^15         8.710 2511947
  200*10^15         8.657 2509779

It seems as if older PARIs ignored high primelimit when sieving
starting from 1.9e17 (which seems to be the GOOD thing to do!)5~.  The
newer version does not do this, so becomes too slow.
Thanks,
Ilya