in reply to Clocking Portion of Your Perl Code

Benchmark::Timer will allow you to wrap timing code around existing code without restructuring and with little impact upon it. It will also accumulate statistics from multiple timed segments in a single run and generate the familiar Benchmark.pm style reports at the end.

Devel::SmallProf profiles code line by line instead sub by sub.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: Clocking Portion of Your Perl Code
by Anonymous Monk on Jun 12, 2005 at 09:37 UTC
    Also how do you benchmark::timer the subroutine:
    my @acc_array; foreach(@somearray){ if($cond ==1) { my $a = Benchmark::Timer->new(skip => 0); $a->start('tag'); @acc_array = &some_long_running_func($_); $a->stop('tag'); print $a->report; } }
    Print this:
    Processed: 1 tag still running at mycode.pl line 223 Processed: 2 tag still running at mycode.pl line 223
    Instead of giving the time. What's wrong with my code?

      There doesn't appear to be anything wrong with your code. It would perhaps be easier to diagnose if we knew which line of your snippet was line 223?

      That said, I generally create a single B::T object at the beginning of the program and the call report at the end. That allows me to time several portions of the code by using different tags.

      I can't see how your use of close scoping would affect the outcome or produce the error you're seeing, but I thought I'd mention it anyway.

      If you don't want to post the real code, then I think you will have to try and produce a small testcase that reproduces the behaviour before we can help you further.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re^2: Clocking Portion of Your Perl Code
by Anonymous Monk on Jun 12, 2005 at 09:22 UTC
    Hi
    It seems that Benchmark::Timer is what I need, but having read your comment:
    with little impact upon it
    I am a bit cautious. What do you mean by that? Is it harmful?
      Is it harmful?

      No. I simple meant that being a call interface rather than a callback interface, it dances your tune rather than you it's. You don't have to restructure everything to us it.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.