Re: Prime[..] slows down

• To: mathgroup at smc.vnet.net
• Subject: [mg53562] Re: [mg53524] Prime[..] slows down
• From: Daniel Lichtblau <danl at wolfram.com>
• Date: Tue, 18 Jan 2005 05:08:02 -0500 (EST)
• References: <200501160207.VAA05705@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```George Szpiro wrote:

>My last posting did not have the program listing:
>
>
>can somebody explain why Prime[...] slows down so drastically and so
>million (see below)?
>
>also: how can I get elapsed time in fractions of seconds? (Timing[...] did
>not work inside the loop for some reason.)AboluteTime to give
>
>Thanks,
>
>George
>george at netvision.net.il
>
>
>Sets=100;
>
>KK=20000;
>
>InitValue=105000000;
>
>Steps=10000;
>
>For[k=1,k<=Sets,k++,
>
>  TT=AbsoluteTime[];
>
>  For[j=1,j<=KK,j++, x=2*Prime[InitValue+k*Steps+j];]
>
>    Print["Prime[",InitValue+k*Steps+j-1,"]=",Prime[InitValue+k*Steps+j-1],"
>Time ",AbsoluteTime[]-TT];
>
>  TT=AbsoluteTime[];]
>
>Prime[105010000]=2145604099 Time 1.00000
>
>Prime[105030000]=2146031753 Time 2.00000
>
>

The jump is explained by the computation below.

In[4]:= PrimePi[2^31]-1
Out[4]= 105097564

So between 105090000 and 105100000 we move from machine integers to
bignums. Performing arithmetic on these is slower.

Daniel Lichtblau
Wolfram Research

```

• Prev by Date: Re: NIntegrate with Minimize
• Next by Date: Re: GUIKit: <<file quirk
• Previous by thread: Re: Prime[..] slows down
• Next by thread: LegendreP -- up to which order?