in reply to Re: code to get the date for "next Thursday"
in thread code to get the date for "next Thursday"

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, });

Replies are listed 'Best First'.
Re^3: code to get the date for "next Thursday"
by bfdi533 (Friar) on Mar 20, 2006 at 22:28 UTC

    Well, the machine that I normally run this on takes 3-5 seconds to run the script. My current laptop runs this pretty quickly but it is also not the "production environment" for this script.

    I will take a look at some of the options as well as the test script to see which one will work best for the target system.

    Thanks!