Permalink
Browse files

Factor Niecza::Benchmark out of perf/

Useful for timing one-liners
  • Loading branch information...
1 parent b3fda07 commit acc5e83d921003d403073481c0248618fbdbf625 @sorear committed Dec 24, 2011
Showing with 3 additions and 4 deletions.
  1. +3 −4 perf/std-20110528.pl6 → lib/Niecza/Benchmark.pm6
@@ -1,3 +1,5 @@
+module Niecza::Benchmark;
+
sub timethis($nr, $fun) {
my $i = -$nr;
my $start = times[0];
@@ -11,10 +13,7 @@ my $base2 = timethis(1000000, sub () {});
my $avg = ($base1 + $base2) / 2;
say "null check: rd = {abs ($base1 - $base2) / $avg} ($base1 $base2)";
-sub bench($name, $nr, $f) {
+sub bench($name, $nr, $f) is export {
my $time = timethis($nr, $f);
say "$name = {($time - $avg)*1e6}µs [{$time*$nr}s / $nr]";
}
-
-my $obj = CLR::System::Random.new;
-bench 'clr op', 100000, sub () { $obj.Next(100, 200); };

0 comments on commit acc5e83

Please sign in to comment.