Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
2k stars 559 forks source link

Division by zero in Benchmark.pm #2384

Closed p5pRT closed 21 years ago

p5pRT commented 24 years ago

Migrated from rt.perl.org#3726 (status was 'resolved')

Searchable as RT3726$

p5pRT commented 24 years ago

From @abigail

Created by @abigail

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)

Perl Info ``` Flags: category=library severity=high Site configuration information for perl v5.6.0: Configured by abigail at Wed Jun 14 21:00:02 EDT 2000. Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration: Platform: osname=linux, osvers=2.2.13, archname=i686-linux-64int uname='linux alexandra 2.2.13 #5 tue feb 8 15:37:54 est 2000 i686 unknown ' config_args='-Dprefix=/opt/perl -d -Uinstallusrbinperl -Doptimize=-g -Dusemorebits' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define use64bitint=define use64bitall=undef uselongdouble=define usesocks=undef Compiler: cc='cc', optimize='-g', gccversion=2.95.2 19991024 (release) cppflags='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include' ccflags ='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64' stdchar='char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long long', ivsize=8, nvtype='long double', nvsize=12, Off_t='off_t', lseeksize=8 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lndbm -lgdbm -ldbm -ldb -ldl -lm -lc -lposix -lcrypt libc=/lib/libc-2.1.2.so, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.6.0: /home/abigail/Perl /home/abigail/Sybase /opt/perl/lib/5.6.0/i686-linux-64int /opt/perl/lib/5.6.0 /opt/perl/lib/site_perl/5.6.0/i686-linux-64int /opt/perl/lib/site_perl/5.6.0 /opt/perl/lib/site_perl/5.005 /opt/perl/lib/site_perl . Environment for perl v5.6.0: HOME=/home/abigail LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH=/home/abigail/Lib:/usr/local/lib:/usr/lib:/lib:/usr/X11R6/lib:/opt/tcl/lib:/opt/tk/lib/tk8.0 LOGDIR (unset) PATH=/home/abigail/Bin:/opt/perl/bin:/opt/tcl/bin:/opt/tk/bin:/usr/local/bin:/usr/local/X11/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/games:/opt/povray/bin:/opt/teTeX/bin/i686-pc-linux-gnu:/opt/python/bin PERL5LIB=/home/abigail/Perl:/home/abigail/Sybase PERLDIR=/opt/perl PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 24 years ago

From @jhi

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.