C.DeRykus wrote:
> On Aug 10, 8:43 am, [email protected] (Ron Bergin) wrote:
[snip]
>>
>> 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
>

Did you run that on Windows or Linux?  I tested it on both
and my results would indicate that the sprintf version is
slower than concatenation and the results were still
flipped between OS's.

I probably should have mentioned that the "Matt" code is
what is currently being used in production and I need to
profile/benchmark it against different approaches.

I haven't profiled it as Chas suggested, but I suspect the
issue is due to the difference in perl versions.

5.8.8 on Linux
5.10.0 on Windows.

My theory is that 5.10.x implemented some optimizations
that improved the speed of strftime.

Ron


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


Reply via email to