develooper Front page | perl.perl5.porters | Postings from February 2000

<patch> avoid division by 0 in Benchmark.pm

From:
Stephane Payrard
Date:
February 10, 2000 06:18
Subject:
<patch> avoid division by 0 in Benchmark.pm
Message ID:
20000124161538.A995@freesurf.fr
tested against perl5.005_63

On too short tests Benchmark makes a division by 0.
Strangely the numerator was tested in place of the denominator:

timethis 1: Illegal division by zero at lib/Benchmark.pm line 438, <IN> line 7.
	Benchmark::timestr(undef, 'Benchmark=ARRAY(0x82cb164)', '', '5.2f') called at lib/Benchmark.pm line 616
	Benchmark::timethis(undef, 1, '{}') called at (eval 13) line 2
	eval '($@, $!, $^E, $,, $/, $\\, $^W) = @saved;package main; $^D = $^D | $DB::db_stop;


After the fix:

timethis 1, "{}"
timethis 1:  0 wallclock secs ( 0.00 usr +  0.00 sys =  0.00 CPU)
            (warning: too few iterations for a reliable count)



diff -u lib/Benchmark.pm.orig lib/Benchmark.pm
--- lib/Benchmark.pm.orig	Wed Dec  8 19:25:49 1999
+++ lib/Benchmark.pm	Mon Jan 24 15:54:47 2000
@@ -435,7 +435,7 @@
 			    $r,$pu,$ps,$pt) if $style eq 'noc';
     $s=sprintf("%2d wallclock secs (%$f cusr + %$f csys = %$f CPU)",
 			    $r,$cu,$cs,$ct) if $style eq 'nop';
-    $s .= sprintf(" @ %$f/s (n=$n)", $n / ( $pu + $ps )) if $n;
+    $s .= sprintf(" @ %$f/s (n=$n)", $n / ( $pu + $ps )) if $pu + $ps;
     $s;
 }
 
I had no time to read p5p recently, sorry for the inconvenience if
this has already been fixed.

-- 
  Stéphane Payrard
   email   : properler@freesurf.fr

  




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About