Re: fastest way to add up a billion numbers

*To*: mathgroup at smc.vnet.net*Subject*: [mg73981] Re: fastest way to add up a billion numbers*From*: "Raj" <rajanikanth at gmail.com>*Date*: Sat, 3 Mar 2007 23:57:38 -0500 (EST)*References*: <esb5js$495$1@smc.vnet.net>

Thanks very much for all the replies. Raj On Mar 2, 11:46 pm, Bill Rowe <readnews... at sbcglobal.net> wrote: > On 3/2/07 at 6:41 AM, rajanika... at gmail.com (Raj) wrote: > > >Could somebody tell me what would be the fastest way to add up a > >billion numbers(from 1 to 10^9 i.e the first billion numbers) in > >Mathematica? > >Ofcourse the answer is n(n+1)/2, but is there any other way in > >Mathematica other than the following one: > >Total@@Range[10^9] > > There are a great many ways. I suspect none is faster or more > efficient than > > In[2]:= > Timing[Sum[n, {n, 1, m}] /. m -> 10^9] > > Out[2]= > {0.11082 Second,500000000500000000} > > Note for smaller lists of numbers it will be faster to actually > sum a list, i.e., > > In[1]:= > data=Range[10000]; > Timing[Total@data] > Timing[Sum[n,{n,1,m}]/.m\[Rule]10000] > > Out[2]= > {0.000297 Second,50005000} > > Out[3]= > {0.11049 Second,50005000} > -- > To reply via email subtract one hundred and four