You do want to use Benchmark. Check out the method timediff.

like this:

use Benchmark; my $start1 = Benchmark->new(); ##Code you want to profile my $end1 = Benchmark->new(); my $diff1 = timediff($end1, $start1); print "Section 1: ", timestr($diff1); my $start2 = Benchmark->new(); ##Next section of code you want to profile my $end2 = Benchmark->new(); my $diff2 = timediff($end2, $start2); print "Section 2: ", timestr($diff2);
Update: slightly better using HoH.
use Benchmark; my ($fn1,$fn2) = @ARGV; my %benchs; my $cnt = 0; $benchs{section_1}{start} = Benchmark->new(); open(FH,$fn1) or die(); while (my $line1 = <FH>) { $cnt++ if ($line1 =~ /\./); } print "$cnt\n"; close FH; $benchs{section_1}{end} = Benchmark->new(); $cnt = 0; $benchs{section_2}{start} = Benchmark->new(); open(FH,$fn2) or die(); while (my $line2 = <FH>) { $cnt++ if ($line2 =~ /\./); } print "$cnt\n"; close FH; $benchs{section_2}{end} = Benchmark->new(); foreach my $b (keys %benchs) { print "$b: " ,timestr(timediff($benchs{$b}{end}, $benchs{$b}{start +})),"\n"; }


grep
Mynd you, mønk bites Kan be pretti nasti...

In reply to Re: performance profiling by grep
in thread performance profiling by thedoe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.