Ilya Zakharevich on Sat, 21 Sep 2024 20:48:42 +0200


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

Re: Suspicious average timing of isprime() (maybe a bug?!)


On Sat, Sep 21, 2024 at 11:46:31AM -0700, Ilya Zakharevich wrote:
> THE METHOD: run isprime() on all pseudoprimes in an interval of length
>     	    20M.  Inspect the timing.

Forgot to include the code:

  fmtTab(s,a) = if(type(a)==type([])||type(a)==type([]~), for(k=1,#a,s=Str(s,"\t",a[k])), #a, if(s!="",s=Str(s,"\t"));s=Str(s,a)); s;
  timeit(f,s="",div=1) = gettime(); my(o=f()); print(fmtTab(Strprintf("%s%7.3f",if(s=="",s,Str(s,"\t")),t=gettime()/1000/div),o)); [t,o];
  my(L=2*10^7,pp,c);for(k=19,23,foreach([1,2,4,8],m,c=0;pp=m*10^k;timeit(()->forprime(p=pp,pp+L,if(isprime(p),c++));c,strprintf("%de%d",m,k),L/10^9)))
  my(L=2*10^7, d=10^7); solve(x=390e18,405e18, my(xx=x\d*d); timeit(()->my(c);forprime(p=xx,xx+L,if(isprime(p),c++));c,xx,L/10^9)[1]-15000)
    
Ilya