From: Hugo van der Sanden Date: Tue, 4 Mar 1997 11:32:11 +0000 (+0000) Subject: Benchmark: using code refs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0d72c55d125e399044812b52df01929239edc03e;p=p5sagit%2Fp5-mst-13.2.git Benchmark: using code refs It often irritates me that I can't supply a coderef to the Benchmark:: routines: here's a small patch to allow them. p5p-msgid: 199703041132.LAA07613@tyree.iii.co.uk --- diff --git a/lib/Benchmark.pm b/lib/Benchmark.pm index c382fcb..ee7cf74 100644 --- a/lib/Benchmark.pm +++ b/lib/Benchmark.pm @@ -329,7 +329,9 @@ sub runloop { last if $pack ne $curpack; } - my $subcode = "sub { package $pack; my(\$_i)=$n; while (\$_i--){$c;} }"; + my $subcode = (ref $c eq 'CODE') + ? "sub { package $pack; my(\$_i)=$n; while (\$_i--){&\$c;} }" + : "sub { package $pack; my(\$_i)=$n; while (\$_i--){$c;} }"; my $subref = eval $subcode; croak "runloop unable to compile '$c': $@\ncode: $subcode\n" if $@; print STDERR "runloop $n '$subcode'\n" if ($debug);