Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Adding Days To YYYYMMDD Date Format

by Tux (Abbot)
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

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 scrutinizing the Monastery: (5)
As of 2016-08-29 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (409 votes). Check out past polls.