like this:
Update: slightly better using HoH.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);
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"; }
In reply to Re: performance profiling
by grep
in thread performance profiling
by thedoe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |