MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: fastest way to add up a billion numbers


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




  • Prev by Date: RE: Combine 2d and 3d plots that has different ranges
  • Next by Date: Re: setting variables from within NDSolve
  • Previous by thread: Re: Re: fastest way to add up a billion numbers
  • Next by thread: Re: Re: fastest way to add up a billion numbers