       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:= movAc[data_, days_] :=
Accumulate[
Prepend[Drop[data, days] - Drop[data, -days],
Tr@Take[data, days]]]/days

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

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

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

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

Out= {1.514497, Null}

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

Out= {0.831964, Null}
Out= {False, 4.89608*10^-14}

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

Out= {0.892764, Null}
Out= {False, 5.38902*10^-13}

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

Out= {0.823370, Null}
Out= {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