Yes, the numbers say that your calculations with Date::Calc run 1300 times faster than your calculations with Date::Manip. You weren't "comparing apples to apples" (the Date::Calc loop doesn't do any "parsing" at all), however, so that speed difference is going to be, at least a bit, overstated.

But much more important than that, is that the numbers say that reparsing two dates and then comparing them can be done in 1/100th of a second with Date::Manip (on your computer with those simple date formats). Because even being 1300-times faster doesn't mean that you'll even notice the difference. (:

So, for example, if we wanted to compute a date difference for each news article as we display it, well, 1/100th of a second vs. 1e-5 seconds isn't going to make a noticeable difference at all. If we want to compute a date difference for thousands of news articles in order to select a dozen articles to list, then this will probably make a quite noticeable difference.

But your benchmarks don't apply at all well to the original problem. If the news articles came with month, day, and year already parse out as numbers, then I probably would just use Time::Local since it just exposes an ANSI-standard-C function.

Given the task of parsing dates in news articles, I'd start with Date::Manip, since that is exactly the kind of problem it was designed for (since Usenet news articles usually have dates encoded in different formats and from different timezones and Date::Manip knows how to take that into account) and using it would require very little coding on my part. If the results seemed slow to me, then I'd look at how much work it would take to use something else and then decide whether it was worth my time to produce enough working code that I could compare the subjective speed difference for my specific task.

        - tye (but my friends call me "Tye")

In reply to (tye)Re: Date comparisons + Benchmark by tye
in thread Date comparisons by cajun

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.