This method appears to be a little bit slower, though neither seem all that "slow" to me. 16+ million iterations per second on my little powerbook seems plenty fast...

Are you sure this is the piece of your code that's slow?

Rate ikegami code bfdi code ikegami code 16393443/s -- -20% bfdi code 20408163/s 24% --
#!/usr/local/bin/perl use Benchmark qw/ timethis cmpthese /; use Date::Manip; use POSIX qw/strftime/; use Time::Local qw/ timegm_nocheck /; sub get_using_date_manip { my $today_dt = &ParseDate("today"); my $new_dt = &Date_GetNext($today_dt, 'Thu', 1); return &UnixDate($new_dt, "%Y-%m-%d"); } sub get_using_posix_and_time_local { my ($sec,$min,$hour,$day,$mon,$year,$wday) = localtime(); # Defaults to now. $year += 1900; $day += (7 - $wday + 4) % 7; $next_th = timegm_nocheck(0,0,0,$mday,$mon,$year); return strftime('%Y-%m-%d', localtime($next_th)); } cmpthese(10_000_000, { 'bfdi code' => &get_using_date_manip, 'ikegami code' => &get_using_posix_and_time_local, });

In reply to Re^2: code to get the date for "next Thursday" by duckyd
in thread code to get the date for "next Thursday" by bfdi533

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.