On Aug 10, 8:43 am, [email protected] (Ron Bergin) wrote:
> While doing some benchmark testing on both Windows and Linux, the
> results of the exact same code was reversed.  A slight difference in
> the percentages is understandable, but I fail to see why the results
> would be reversed.  Could someone shed some light on this issue?
>
> First the benchmark results:
>
> C:\TEMP>timestamp.pl
>          Rate Matt  Ron
> Matt 162840/s   -- -37%
> Ron  257003/s  58%   --
>
> [r...@099vicidial101 ~]# ./timestamp.pl
>          Rate  Ron Matt
> Ron  110132/s   -- -29%
> Matt 155763/s  41%   --
>
> The code:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use POSIX qw(strftime);
> use Benchmark qw(:all);
>
> my $count = 1_000_000;
>
> cmpthese($count, {
>     Matt => \&matt,
>     Ron  => \&ron,
>
> });
>
> sub matt {
>     my $now_date_epoch = time();
>     my $BDtarget = ($now_date_epoch - 5);
>     my ($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst)
> = localtime($BDtarget);
>     $Byear = ($Byear + 1900);
>     $Bmon++;
>     if ($Bmon < 10) {$Bmon = "0$Bmon";}
>     if ($Bmday < 10) {$Bmday = "0$Bmday";}
>     if ($Bhour < 10) {$Bhour = "0$Bhour";}
>     if ($Bmin < 10) {$Bmin = "0$Bmin";}
>     if ($Bsec < 10) {$Bsec = "0$Bsec";}
>     my $BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec";
>
> }
>
> sub ron {
>     my $BDtsSQLdate = strftime("%Y%m%d%H%M%S", localtime(time() -
> 5) );
>
> }

I think there was also a thread about string concatenation
being horrifically slow on comp.lang.perl.misc.

sprintf provides a substantial speedup...maybe less
malloc'ing on Win32. Fewer perl op's probably help
too:

  sub matt {
    my $now_date_epoch = time();
    my $BDtarget = ($now_date_epoch - 5);
    my ($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear) =
localtime($BDtarget);
    $Byear = ($Byear + 1900);
    $Bmon++;

    my $BDtsSQLdate = sprintf "%4d%02d%02d%02d%02d%02d",
                $Byear,$Bmon,$Bmday, $Bhour,$Bmin, $Bsec;
  }

         Rate Matt  Ron
Matt 323729/s   -- -13%
Ron  372717/s  15%   --

Matt 323834/s   -- -13%
Ron  370508/s  14%   --

Matt 323834/s   -- -13%
Ron  370508/s  14%   --

Matt 328731/s   -- -11%
Ron  370645/s  13%   --

--
Charles DeRykus


--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to