Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

What? You're going to compare 16 lines of unrelated code (which contains a nasty loop) to a single line function and call it a benchmark victory? The OP was looking for a quick date time increment. His solution contained this and plenty of other code not directly related to the date time increment. If you're going to benchmark you won't get very far comparing apples to oranges.

By my benchmarking, the OP's "equivalent datetime increment" code is 144 times faster than DateTime and nearly as fast as Date::Calc.

use strict; use warnings; use DateTime; use Date::Calc qw (Add_Delta_DHMS); use Benchmark qw(cmpthese); my $dt = DateTime->new( year => 2011, month => 1, day => 1, hour => 0, minute => 0, second => 0, ); my ($year, $month, $day, $hour, $min, $sec) = (2011, 1, 1, 0, 0, 0); my ($mday, $mon, $wday, $yday, $isdst); my $time = time(); cmpthese( -1, { 'DateTime' => sub { $dt->add(hours => 1, minutes => 2, seconds => 3); }, 'Date::Calc' => sub { ($year, $month, $day, $hour, $min, $sec) = Add_Delta_DHMS($year, $month, $day, $hour, $min, $sec, 0, 1, 2 +, 3); }, 'tsk1979' => sub { $time += 3723; # 1 * 60 * 60 + 2 * 60 + 3 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time); }, } ); __END__ Rate DateTime tsk1979 Date::Calc DateTime 2875/s -- -99% -99% tsk1979 431483/s 14910% -- -18% Date::Calc 526429/s 18213% 22% --

It's a good habit to check that your Benchmark code is equivalent before making bold claims about your Benchmark results.


In reply to Re^2: Solution found! by ruzam
in thread Simple date and time manipulation by tsk1979

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (12)
    As of 2019-07-15 17:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?