Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Special case mktime: semi-sequential access

by RichardK (Vicar)
on Jul 01, 2013 at 12:40 UTC ( #1041838=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Special case mktime: semi-sequential access
in thread Special case mktime: semi-sequential access

Yep, that's very interesting, I get similar sorts of results here but mktime only takes 33 seconds. my machine isn't that new so I don't know why there such a big difference. I'm running perl v5.16 on 64 bit Linux.

mktime seems to stat /etc/localtime every time so that's where the system time is coming from, it's odd that it isn't cached, but I don't think I want to delve into the depths of the posix library to find out more ;).

I guess you could tweak your code a little bit, if you're after every last cycle :-

A valid $day can never be zero so there no point testing if $mk_day > 0, $mk_day == $day is enough

and if you create your times for midnight i.e.  $time = POSIX::mktime(0, 0, 0, $day, $mon, $year); then you can drop $mk_hms and save yourself one whole subtraction :)


Comment on Re^3: Special case mktime: semi-sequential access
Download Code
Replies are listed 'Best First'.
Re^4: Special case mktime: semi-sequential access
by flexvault (Prior) on Jul 01, 2013 at 13:03 UTC

    RichardK,

    Good point about using midnight of the specific day, and you could use a hash for saving(caching) each different date. That way you only need to call 'POSIX::mktime' once per day.

    Interesting!

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin

Re^4: Special case mktime: semi-sequential access
by not_japh (Novice) on Jul 01, 2013 at 14:50 UTC
    Good observation about using midnight. Done. The mk_day was to detect a startup condition, but that can go too. The only remaining case is handling mktime(0,0,0,0,0,0) which should return undef.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (12)
As of 2015-07-31 04:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls