Your version is more compact and satisfying, but it's slower because it missed the point (probably because I didn't state it!). Mine is not not memoizing, so perhaps calling it caching_* was a poor choice.

You can do math to avoid calling mktime not just in the cases it's seen, but also for other times within the same day. The math is simply this: if you know any epoch time in some day of interest, and you know what HMS that maps to, you can do two multiplies and a few adds to find a new epoch for a new HMS in that same day.

Benchmark: timing 5 iterations of FastMktime::caching_mktime, FastMkti +me::new_caching_mktime, POSIX::mktime, TIME::Local::timegm_nocheck... FastMktime::caching_mktime: 65 wallclock secs (64.36 usr + 0.02 sys = + 64.38 CPU) @ 0.08/s (n=5) FastMktime::new_caching_mktime: 220 wallclock secs (157.44 usr + 62.10 + sys = 219.54 CPU) @ 0.02/s (n=5) POSIX::mktime: 122 wallclock secs (60.43 usr + 60.86 sys = 121.29 CPU) + @ 0.04/s (n=5) TIME::Local::timegm_nocheck: 141 wallclock secs (140.86 usr + 0.30 sy +s = 141.16 CPU) @ 0.04/s (n=5)

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.