MathGroup Archive 2006

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

Search the Archive

Re: How to sum up this list fast, Total, Fold is still slow to me

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66455] Re: How to sum up this list fast, Total, Fold is still slow to me
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sun, 14 May 2006 02:57:28 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <e3shbu$m15$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

phd related wrote:
> Hi, guys
>       i am trying to sum up a large list of 24,000 elements which are very
> small. See the attachment for details i have tried
> 
> [ contact the author to get the attachment - moderator]
> 
> Plus@@longlist
> or Total[longlist]
> or Fold[Plus,0,longlist]
> but it is still slow to me
> 
> How to tackle this problem
>  Thanks for your help
> 
> 
Not sure what you mean by "very slow" but it might be due to the 
arithmetic used.

The first set of timings -- I have added the *Trace* function -- is for 
a list of 100,000 small numbers expressed in machine precision. For the 
second set, a list of 100,000 numbers expressed with 100 significant 
digits has been used. Finally, the last set uses exact arithmetic: 
numbers are expressed as rational.

You can see that the third case took a very long time to compute and 
that the timing can be deemed as independent of the function used to sum 
up the list. It might be what you face in your case.

In[1]:=
longlist = Table[N[1/Random[Integer, {1000, 100000}]], {10^5}];
Timing[Plus @@ longlist][[1]]
Timing[Total[longlist]][[1]]
Timing[Fold[Plus, 0, longlist]][[1]]
Timing[Tr[longlist]][[1]]

Out[2]=
0.016 Second

Out[3]=
0.016 Second

Out[4]=
0.015 Second

Out[5]=
0. Second

In[6]:=
longlist = Table[SetPrecision[1/Random[Integer, {1000, 100000}], 100],
     {10^5}];
Timing[Plus @@ longlist][[1]]
Timing[Total[longlist]][[1]]
Timing[Fold[Plus, 0, longlist]][[1]]
Timing[Tr[longlist]][[1]]

Out[7]=
0.094 Second

Out[8]=
0.094 Second

Out[9]=
0.109 Second

Out[10]=
0.094 Second

In[11]:=
longlist = Table[1/Random[Integer, {1000, 100000}], {10^5}];
Timing[Plus @@ longlist][[1]]
Timing[Total[longlist]][[1]]
Timing[Fold[Plus, 0, longlist]][[1]]
Timing[Tr[longlist]][[1]]

Out[12]=
20.187 Second

Out[13]=
20.094 Second

Out[14]=
20.313 Second

Out[15]=
20.109 Second

HTH,
Jean-Marc


  • Prev by Date: Re: Limit Question
  • Next by Date: Re: Re: Re: )
  • Previous by thread: How to sum up this list fast, Total, Fold is still slow to me
  • Next by thread: Rules