Re: fastest way to add up a billion numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg73923] Re: [mg73880] fastest way to add up a billion numbers
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sat, 3 Mar 2007 01:03:40 -0500 (EST)
- References: <200703021141.GAA04040@smc.vnet.net>
On 2 Mar 2007, at 12:41, Raj wrote:
> hi!
>
> 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]
>
> Thanks,
>
> Raj
>
>
Sum[i,{i,1,10^9}]//Timing
{0.122547 Second,500000000500000000}
or much faster
In[3]:=
Timing[NSum[i, {i, 1, 10^9}]]
Out[3]=
{0.0021539999999999893*Second, 5.000000005*^17}
ANdrzej Kozlowski
- References:
- fastest way to add up a billion numbers
- From: "Raj" <rajanikanth@gmail.com>
- fastest way to add up a billion numbers