MathGroup Archive 2010

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

Search the Archive

Re: Speed Up of Calculations on Large Lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108988] Re: Speed Up of Calculations on Large Lists
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Fri, 9 Apr 2010 03:32:45 -0400 (EDT)
  • References: <hpcjh0$mva$1@smc.vnet.net> <hphq5f$1h6$1@smc.vnet.net>

On Apr 7, 4:26 am, sheaven <karg.ste... at googlemail.com> wrote:
> I did some testing and here is the outcome:
>
> [...]
>
> Drop is by far the fastest function

You didn't give ListConvolve a fair test, because you defined the
kernel as a list of exact rationals. If you define it as a list of
reals, ListConvolve is just as fast as drop-type methods and does
not lose precision.

In[1]:= movAc[data_, days_] :=
 Accumulate[
   Prepend[Drop[data, days] - Drop[data, -days],
    Tr@Take[data, days]]]/days

In[2]:= maDropF =
  Function[{vData, days},
   With[{vAcc = Prepend[Accumulate@vData, 0.]},
    Developer`ToPackedArray[(Drop[vAcc, days] - Drop[vAcc, -days])/
      days, Real]]];

In[3]:= moCon[data_, days_] :=
 ListConvolve[ConstantArray[1./days, days], data]

In[4]:= data = 100 + Accumulate[RandomReal[{-1, 1}, {1*^4}]] ;

In[5]:= AbsoluteTiming[
 m0 = Table[MovingAverage[data, days], {days, 30, 250}];]

Out[5]= {1.514497, Null}

In[6]:= AbsoluteTiming[
 m1 = Table[movAc[data, days], {days, 30, 250}];]
{m1 == m0, Max@Abs[m1/m0 - 1]}

Out[6]= {0.831964, Null}
Out[7]= {False, 4.89608*10^-14}

In[8]:= AbsoluteTiming[
 m2 = Table[maDropF[data, days], {days, 30, 250}];]
{m2 == m0, Max@Abs[m2/m0 - 1]}

Out[8]= {0.892764, Null}
Out[9]= {False, 5.38902*10^-13}

In[10]:= AbsoluteTiming[
 m3 = Table[moCon[data, days], {days, 30, 250}];]
{m3 == m0, Max@Abs[m3/m0 - 1]}

Out[10]= {0.823370, Null}
Out[11]= {True, 1.11022*10^-16}


  • Prev by Date: Mathematica's beauty
  • Next by Date: Re: How to enter an integral in a formula and have mathematica *not*
  • Previous by thread: Re: Speed Up of Calculations on Large Lists
  • Next by thread: Intel MKL 10