MathGroup Archive 2002

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

Search the Archive

Summing a list of real numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33416] Summing a list of real numbers
  • From: "Coleman, Mark" <mark.coleman at dri-wefa.com>
  • Date: Wed, 20 Mar 2002 01:53:42 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Greetings,

In the course of working on an optimization problem that involves summing large lists of real numbers, a colleague of mine came across an interesting result. We compared the computational speed of different methods for summing lists:

   (1) Apply[Plus, mylist]
   
    (2) Dot[mylist,ListofOnes], where ListofOnes is a list of of size N of 1.0's

    (3) Tr[mylist], where Tr is the built-in matrix trace operator.

Based on our tests (where list sizes range from 100,000 to 1,000,000 elements), Method (3) is far and away the fastest. On average (3) is 5x faster than Method (2), and over 70x faster than Method (1). 

I was curious if anyone could offer an explanation.

Thanks,

-Mark


  • Prev by Date: Re: newbie question - printing Pi
  • Next by Date: the fastest way to read binary files
  • Previous by thread: Re: Problem with 3D Polygon
  • Next by thread: Re: Summing a list of real numbers