Skip to content

Commit

Permalink
Added basic subroutines for timing things
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpilot committed May 26, 2009
1 parent 471e136 commit 1896a1c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/Benchmark.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Benchmark;

my sub time_it (Int $count where { $_ > 0 }, Code $code) {
my $start-time = time;
for 1..$count { $code.(); }
my $end-time = time;
my $difference = $end-time - $start-time;
my $average = $difference / $count;
return ($start-time, $end-time, $difference, $average);
}

multi sub timethis (Int $count, Str $code) is export {
my $routine = eval "sub \{ {$code} \}";
return time_it($count, $routine);
}

multi sub timethis (Int $count, Code $code) is export {
return time_it($count, $code);
}

sub timethese (Int $count, %h) is export {
my %results;
for %h.kv -> $k, $sub {
%results{$k} = timethis($count, $sub);
}
return %results;
}

0 comments on commit 1896a1c

Please sign in to comment.