Closed p5pRT closed 21 years ago
When running benchmark programs\, I sometimes encounter:
Illegal division by zero at /opt/perl/lib/5.6.0/Benchmark.pm line 584.
I've looked at the Benchmark code\, but the number of short variables and cryptic comments confuse me to much to understand what the intent is. This is line 584:
my $r = $tmax / $ttot - 1; # Linear approximation.
Here's a program which triggers the error (but I expect it to be system dependent).
#!/opt/perl/bin/perl -w
use strict; use Benchmark; use Algorithm::Numerical::Shuffle qw/shuffle/;
use vars qw /@sorted @reverse @organ @rev_organ @random/;
my $size = 100000; # @sorted = map {sprintf "%06d" => $_} 1 .. $size; @sorted = 1 .. $size; # duh! @reverse = reverse @sorted; @organ = (@sorted [1 .. $size/2]\, reverse @sorted [1 .. $size/2]); @rev_organ = (@reverse [1 .. $size/2]\, reverse @reverse [1 .. $size/2]); @random = shuffle @sorted;
timethese -20 => { sorted => 'my @a = sort @::sorted'\, reverse => 'my @a = sort @::reverse'\, # organ => 'my @a = sort @::organ'\, # rev_organ => 'my @a = sort @::rev_organ'\, random => 'my @a = sort @::random'\, }
__END__
(The same happens with bleedperl)
On Thu\, Aug 17\, 2000 at 03:48:54PM -0000\, abigail@foad.org wrote:
This is a bug report for perl from abigail@foad.org\, generated with the help of perlbug 1.28 running under perl v5.6.0.
----------------------------------------------------------------- [Please enter your report here]
When running benchmark programs\, I sometimes encounter:
Illegal division by zero at /opt/perl/lib/5\.6\.0/Benchmark\.pm line 584\.
I've looked at the Benchmark code\, but the number of short variables and cryptic comments confuse me to much to understand what the intent is. This is line 584:
my $r = $tmax / $ttot \- 1; \# Linear approximation\.
That particular code tries to compute how much time it still must spend (and from that derive how many rounds ($n) it still must spend). If $ttot is zero it means that the last batch size $n of tests ran in zero time. Just surronding the last three lines of the while() loop with 'if ($ttot) { ... }' might help.
Migrated from rt.perl.org#3726 (status was 'resolved')
Searchable as RT3726$