Interesting that you decided to cache at the hour level, rather than the day.

I chose the hour and not the day because it ended up producing a "reasonable" number of entries in the cache, as I typically deal with data spread over 30 days my cache is usually around 720 entires. If you are dealing with times that are spread over only a day then I would suggest you go to the minute level of resolution, which would mean a cache around 1440 entries (both numbers are actually low when you factor in the behaviour of perls hashes and the amount of space actually used up).

As for the analysis side of it I think its pretty clear. We are both manipulating strings. A hash lookup on a string of the sizes we are dealing with is far less work than dissescting the string into the required sizes and order (and perhaps supplying additional values) pushing them onto the stack, having timelocal pull them off the stack, build a fragment that it can use to check its cache and return the value over stack again. If you add it up its probably 4 or 5 times more operations (depending on how you defined the term) to call the subroutine, which in both of our cases will most likely be for a time we have already encountered.


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

In reply to Re: Re: Re: Re: Re: Adventures in optimization (or: the good and bad side of being truly bored) by demerphq
in thread Adventures in optimization (or: the good and bad side of being truly bored) by revdiablo

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.