MathGroup Archive 2004

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

Search the Archive

Re: Timing of statements inside a cell

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50853] Re: [mg50841] Timing of statements inside a cell
  • From: DrBob <drbob at bigfoot.com>
  • Date: Fri, 24 Sep 2004 04:41:27 -0400 (EDT)
  • References: <200409230927.FAA08079@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

I haven't tested it, but something like this may help:

Clear[time]
Attributes[time]={HoldAll};
time[expr_,tag_]:=Module[{results=Timing[expr]},
     Sow[First@results/Second,tag];
     Last@results
     ]

Reap@While[
   time[averagePrimerDistance<Mean[Rest@prposBin-Most@prposBin],"Mean"],
   time[pr=random[currentTargetPartitioned],"random"];
   time[prpos=Position[currentTargetPartitioned,pr],"Position"];
   time[prposBin=Sort[Flatten[Append[prposBin,Flatten[prpos]]]],"Sort"]];

Notice that I rewrote the Mean distance test. Most is new in version 5.

There's a granularity issue with Timing that may give you zeroes for most statements. You'll need to total or average each series of Timing outputs.

I also removed unnecessary parentheses and semicolons.

Bobby

On Thu, 23 Sep 2004 05:27:24 -0400 (EDT), János <janos.lobb at yale.edu> wrote:

> Hi,
>
> I have a cell with some code in it containing many statements.  Like:
>
> Cell starts here
> ...
> ...
> currentTargetPartitioned = Partition[currentTarget, primerLength, 1];
> prposBin = {{1}, {currentTargetLength}};
>
> (* Do as long as the Mean of
> the distance between
>      neighbouring primers is bigger than averagePrimerDistance *)
> While[Mean[Flatten[Map[#[[2]] - #[[1]] &, Partition[prposBin, 2, 1]]] ]
>  > \
> averagePrimerDistance, (
>        pr = random[currentTargetPartitioned];
>        prpos = Position[currentTargetPartitioned, pr];
>        prposBin = Sort[Flatten[Append[prposBin, Flatten[prpos] ] ] ];
>        )];
>
> (* Create a double strand
>              from the currentTarget in such a way that the double starts
> from
>        the first primer position and file it into collectedDnaBin *)
> prposBinDouble = Most[Map[{#, Last[prposBin]} &, prposBin] ];
> collectpr = Take[currentTarget, prposBinDouble[[2]] ];
> ...
> ...
> Cell ends here
>
> I would like to time every single statement as they are executing.
> Just adding //Timing after every statement  or wrapping them with
> Timing[statement;] does not work.
> Any good hint ?  /I am sure I am not the only one needing it :)/
>
> In general,  what kind of profiling Mathematica allows to pinpoint the
> statements inside a single cell which spend the most time in the kernel
> ?
>
> If it cannot be done inside a cell, what is possible baring to break
> the cell into single statements cells ?  What should I read ?
>
> Other question:  In the While loop above I am collecting positions into
> a list
>        prposBin = Sort[Flatten[Append[prposBin, Flatten[prpos] ] ] ];
> /Just realized that I should do the Sort outside of the loop :)/
> How can I do the collection with Sow and Reap to avoid Append ?
>
> Thanks ahead,
>
> János
> P.S.
> ----------------------------------------------
> Trying to argue with a politician is like lifting up the head of a
> corpse.
> (S. Lem: His Master Voice)
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Timing of statements inside a cell
  • Next by Date: Re: Re: Re: Re: Re: Forcing a Derivative
  • Previous by thread: Re: Timing of statements inside a cell
  • Next by thread: (Remote connection failed) FrontEnd is listing on wrong port?