From: Anno Siegel Date: Thu, 4 Nov 2004 20:12:36 +0000 (+0000) Subject: [perl #32327] Benchmark calls coderef with spurious arguments X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f265d4dfe284890d5302420b249c71f5ed34f66a;p=p5sagit%2Fp5-mst-13.2.git [perl #32327] Benchmark calls coderef with spurious arguments From: Anno Siegel (via RT) Message-ID: p4raw-id: //depot/perl@23473 --- diff --git a/lib/Benchmark.pm b/lib/Benchmark.pm index d48f8f2..ad04a75 100644 --- a/lib/Benchmark.pm +++ b/lib/Benchmark.pm @@ -435,7 +435,7 @@ our(@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION); clearcache clearallcache disablecache enablecache); %EXPORT_TAGS=( all => [ @EXPORT, @EXPORT_OK ] ) ; -$VERSION = 1.06; +$VERSION = 1.07; # --- ':hireswallclock' special handling @@ -648,7 +648,7 @@ sub runloop { # &runloop a lot, and thus reduce additive errors. my $tbase = Benchmark->new(0)->[1]; while ( ( $t0 = Benchmark->new(0) )->[1] == $tbase ) {} ; - &$subref; + $subref->(); $t1 = Benchmark->new($n); $td = &timediff($t1, $t0); timedebug("runloop:",$td); diff --git a/lib/Benchmark.t b/lib/Benchmark.t index 8081476..3a7a1de 100644 --- a/lib/Benchmark.t +++ b/lib/Benchmark.t @@ -8,7 +8,7 @@ BEGIN { use warnings; use strict; use vars qw($foo $bar $baz $ballast); -use Test::More tests => 193; +use Test::More tests => 194; use Benchmark qw(:all); @@ -42,6 +42,11 @@ is ($foo, 5, "benchmarked code was run 5 times"); isa_ok(timeit(5, '++$bar'), 'Benchmark', "timeit eval"); is ($bar, 5, "benchmarked code was run 5 times"); +# is coderef called with spurious arguments? +timeit( 1, sub { $foo = @_ }); +is ($foo, 0, "benchmarked code called without arguments"); + + print "# Burning CPU to benchmark things will take time...\n";