Re: Prime[..] slows down

*To*: mathgroup at smc.vnet.net*Subject*: [mg53540] Re: [mg53524] Prime[..] slows down*From*: DrBob <drbob at bigfoot.com>*Date*: Sun, 16 Jan 2005 22:23:57 -0500 (EST)*References*: <200501160207.VAA05705@smc.vnet.net>*Reply-to*: drbob at bigfoot.com*Sender*: owner-wri-mathgroup at wolfram.com

Timing works inside the loop just fine: Sets = 10; KK = 20000; InitValue = 105000000; Steps = 10000; For[k = 1, k <= Sets, k++, Print@Timing@For[j = 1, j <= KK, j++, x = 2*Prime[InitValue + k*Steps + j]]] {0.172 Second,Null} {0.188 Second,Null} {0.281 Second,Null} {0.172 Second,Null} {0.422 Second,Null} {0.203 Second,Null} {0.172 Second,Null} {0.906 Second,Null} {2.641 Second,Null} {4.187 Second,Null} or Sets=10; KK=20000; start=105000000; Steps=10000; limits={First@#,Last@#}&; Do[start+=Steps; Print@{start+1,start+KK,First@Timing@ Do[2*Prime@i,{i,start+1,start+KK}]},{Sets}] {105010001,105030000,0.11 Second} {105020001,105040000,0.093 Second} {105030001,105050000,0.219 Second} {105040001,105060000,0.094 Second} {105050001,105070000,0.344 Second} {105060001,105080000,0.14 Second} {105070001,105090000,0.094 Second} {105080001,105100000,0.813 Second} {105090001,105110000,2.562 Second} {105100001,105120000,4.047 Second} As for why Prime slows down... it clearly HAS to slow down as the argument gets larger; precisely when and how much can depend on all sorts of implementation details we're not privy to. Bobby On Sat, 15 Jan 2005 21:07:53 -0500 (EST), George Szpiro <george at netvision.net.il> wrote: > > My last posting did not have the program listing: > > > can somebody explain why Prime[...] slows down so drastically and so > abruptly at about 105 > 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 > > > > -- DrBob at bigfoot.com www.eclecticdreams.net

**References**:**Prime[..] slows down***From:*George Szpiro <george@netvision.net.il>