Re: Speed Up of Calculations on Large Lists
- To: mathgroup at smc.vnet.net
- Subject: [mg108958] Re: Speed Up of Calculations on Large Lists
- From: Ray Koopman <koopman at sfu.ca>
- Date: Thu, 8 Apr 2010 08:01:55 -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
movAc is just as fast as maDropF, and its worst case
has one digit more precision than maDropF's worst case.
In[1]:= << Developer`
In[2]:= movAc[data_, days_] :=
Accumulate[
Prepend[Drop[data, days] - Drop[data, -days],
Tr@Take[data, days]]]/days
In[3]:= maDropF =
Function[{vData, days},
With[{vAcc = Prepend[Accumulate@vData, 0.]},
ToPackedArray[(Drop[vAcc, days] - Drop[vAcc, -days])/days,
Real]]];
In[4]:= PackedArrayQ[
data = 100 + Accumulate[RandomReal[{-1, 1}, {1*^4}]] ]
Out[4]= True
In[5]:= AbsoluteTiming[
m0 = Table[MovingAverage[data, days], {days, 30, 250}];]
Out[5]= {1.500583, Null}
In[6]:= AbsoluteTiming[
m1 = Table[movAc[data, days], {days, 30, 250}];]
{m1 == m0, Max@Abs[m1/m0 - 1]}
Out[6]= {0.792954, Null}
Out[7]= {False, 1.60982*10^-14}
In[8]:= AbsoluteTiming[
m2 = Table[maDropF[data, days], {days, 30, 250}];]
{m2 == m0, Max@Abs[m2/m0 - 1]}
Out[8]= {0.820129, Null}
Out[9]= {False, 1.93734*10^-13}