Eugene van der Pijll <[EMAIL PROTECTED]> wrote:

> I've just uploaded version 0.02 of DateTime::Calendar::Julian,
> incorporating the comments of Tatsuhiko Miyagawa, Dave Rolsky
> and others. All feedback is of course welcome.
>
> Eugene
>
>  From the change log:
>
> 0.02  2003-02-16
>     - replaced POSIX::floor with a homegrown version

If you want to speed things up, it is better to remove the
_floor() function and use int().  I compared the current version
of _ymd2rd() with a new one avoiding _floor() and the results
were, for 1000 RD values which were processed 1000 times each:

  Benchmark: timing 1000 iterations of sub1, sub2...
      sub1: 12 wallclock secs (10.67 usr +  0.00 sys = 10.67 CPU) @ 93.68/s (n=1000)
      sub2: 11 wallclock secs ( 9.38 usr +  0.00 sys =  9.38 CPU) @ 106.56/s (n=1000)

Here is the new, faster _ymd2rd() which avoids _floor():

    sub _ymd2rd {
        my ($self, $y, $m, $d) = @_;

        if ($m <= 2) {
            $m += 12;
            $y--;
        }

        my $k = int($y/4 - 1);
        $y -= 4*$k;

        my $rd = $d + $start_of_month[$m-3] + 365*$y + int($y/4) + 1461*$k - 308;
        return $rd;
    }

A similar change can be done to _rd2ymd to avoid the two calls to
_floor().

Peter

-- 
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;

Reply via email to