[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

RE: [FWP] Factorial Elegance



these are work boxes, and didn't have Tie::Math installed.  but got some
interesting results.
On beer, abigail's routine was faster, however on wickedwitch my routine was
faster.
Our routines are fairly similar which is why i thought the benchmark results
were interesting.

beer is a pentium 3 500Mhz 512kb cache running redhat
cat /proc/version
Linux version 2.2.16-3 (root@porky.devel.redhat.com) (gcc version
egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)) #1 Mon Jun 19 19:11:44 EDT
2000

wickedwitch is a dual pentium 3 850Mhz with 256kb cache per processor
cat /proc/version
Linux version 2.2.14-5.0.14csmp (root@load170.var.com) (gcc version
egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)) #1 SMP Wed May 31 09:23:37
PDT 2000

my test program and benchmarks:



    use strict;
    use Benchmark;


    sub klement {
      return eval join "*", 1 .. shift;
    }

    my @cache = (1);
    sub tayers {
      my $x = shift;
      @cache = (1);
      return undef if $x < 0;
      unless (defined $cache[$x]) {
        my $p = $cache[$#cache];
        $cache[$_] = $p *= $_ for ($#cache+1..$x);
      }
      return $cache[$x];
    }

    sub abigail {
        my ($r  => $x) = (1, shift);
        do {$r *=  $x} while $x -- > 2;
        $r;
    }

sub josh {
  my $x=shift;
  my $l=$x;
  while ($l>1){$x*=--$l};
  $x;
}

    timethese(-5,
     {
      klement => "klement(170);",
      tayers  => "tayers(170);",
      abigail => "abigail(170);",
      josh    => "josh(170);"
     });

    __END__

josh@beer ~/pers$ perl fwpfactorial.pl
Benchmark: running abigail, josh, klement, tayers, each for at least 5 CPU
seconds...
   abigail:  8 wallclock secs ( 4.92 usr +  0.09 sys =  5.01 CPU) @
5072.85/s (n=25415)
      josh:  7 wallclock secs ( 4.93 usr +  0.08 sys =  5.01 CPU) @
5705.79/s (n=28586)
   klement:  7 wallclock secs ( 4.97 usr +  0.03 sys =  5.00 CPU) @ 314.20/s
(n=1571)
    tayers:  7 wallclock secs ( 4.92 usr +  0.08 sys =  5.00 CPU) @
2194.20/s (n=10971)

josh@wickedwitch ~/pers$ perl fwpfactorial.pl
Benchmark: running abigail, josh, klement, tayers, each for at least 5 CPU
seconds...
   abigail:  5 wallclock secs ( 4.91 usr +  0.16 sys =  5.07 CPU) @
9180.28/s (n=46544)
      josh:  7 wallclock secs ( 4.80 usr +  0.21 sys =  5.01 CPU) @
8837.92/s (n=44278)
   klement:  5 wallclock secs ( 4.83 usr +  0.17 sys =  5.00 CPU) @ 656.20/s
(n=3281)
    tayers:  7 wallclock secs ( 5.02 usr +  0.09 sys =  5.11 CPU) @
4007.44/s (n=20478)


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe