Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Adding Days To YYYYMMDD Date Format

by Tux (Monsignor)
on May 17, 2012 at 07:36 UTC ( #971000=note: print w/ replies, xml ) Need Help??


in reply to Re: Adding Days To YYYYMMDD Date Format
in thread Adding Days To YYYYMMDD Date Format

When doing a lot of these calculations with dates, keeping the dates in a standard localtime list can prove very useful. When iso-dates are to be generated like in this example, calculation is faster than printf:

use Benchmark qw(cmpthese); my @d = localtime; cmpthese (-1, { prnt => sub { my $x = sprintf "%d%02d%02d", 1900 + $d[5], $d[4] + 1, $d[3]; }, calc => sub { my $x = (($d[5] + 1900) * 100 + $d[4] + 1) * 100 + $d[3]; }, }); => Rate prnt calc prnt 2025658/s -- -37% calc 3215550/s 59% --

And yes, I did have a long running process where millions of these were done, so it did matter.


Enjoy, Have FUN! H.Merijn


Comment on Re^2: Adding Days To YYYYMMDD Date Format
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://971000]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-09-01 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (6 votes), past polls