MathGroup Archive 2006

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

Search the Archive

speed of evaluation of an instruction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64961] speed of evaluation of an instruction
  • From: rudy <rud-x at caramail.com>
  • Date: Fri, 10 Mar 2006 05:14:53 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

hello,

To sort a list I utilize these instructions:

t = Split[testList];
t = t /. x : {1 ..} :> {1, Rest[x] /. 1 -> 0} // Flatten;
Position[t, 1] // Flatten; 

But there's something I don't understand at all.
If I do:

In > testList = Table[Random[Integer], {100000}];

In > t = Split[testList];
     t = t /. x : {1 ..} :> {1, Rest[x] /. 1 -> 0} // Flatten;
     Position[t, 1] // Flatten; // Timing

Out > {0.062 Second, Null}

cool: it's quick!... but if I do then: 

In > rapid[l_List] := Module[{t = Split[l], x, res},
     t = t /. x : {1 ..} :> {1, Rest[x] /. 1 -> 0} // Flatten;
     res = Position[t, 1] // Flatten]

In > rapid[testList];//Timing

Out > {0.344 Second, Null}

It's 5 times slower...!?
Nevertheless the only difference between the two cases is in the second the instruction is executed inside a Module...

That's not all:
We should think this is caused by the fact we execute an instruction inside a function ("rapid"), but if we do:

In > Position[
              Split[testList] /.
                                 x : {1 ..} :> 
                                            {1, Rest[x] /. 1 -> 0} 
                                            // Flatten, 1
             ] // Flatten; // Timing

Out > {0.468 Second, Null}

It's again slower!...

Could anybody expalin this ?
Thanks all
Rudy


  • Prev by Date: Re: Fastest method for comparing overlapping times in random time series
  • Next by Date: Re: Mathematica and Education
  • Previous by thread: Re: first variation of the functional
  • Next by thread: Re: speed of evaluation of an instruction