Tommi M�kitalo sent the following bits through the ether:

> Then you can do perl -e 'use Math::Log10; print log10(43.2);', which is 3 
> times faster than perl -e 'use POSIX qw(log10); print log10(43.2);'.

Did someone say something about a benchmark?

#!/usr/bin/perl -w
use strict;
use Benchmark qw(cmpthese);
use POSIX qw(log10);

cmpthese(-10, {
  'POSIX' => sub {
    foreach my $i (1..100) {
      my $x = log10($i);
    }
  },
  'Perl' => sub {
    foreach my $i (1..100) {
      my $x = log($i)/log(10);
    }
  },
});

Which on my computer gives:
Benchmark: running POSIX, Perl for at least 10 CPU seconds...
     POSIX:  1 wallclock secs (10.67 usr +  0.01 sys = 10.68 CPU) @ 369.85/s (n=3950)
      Perl:  1 wallclock secs (10.69 usr +  0.01 sys = 10.70 CPU) @ 413.74/s (n=4427)
       Rate POSIX  Perl
POSIX 370/s    --  -11%
Perl  414/s   12%    --

Leon

ps I think a module for this is a little over the top, however 
   I note that Python has log10 in its math package, Ruby
   has log10 in its Math package, and Java does not ship log10
   in java.lang.Math.
-- 
Leon Brocard.............................http://www.astray.com/
scribot.................................http://www.scribot.com/

... Barium: what you do with dead chemists

Reply via email to