Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

rjt's scratchpad

by rjt (Deacon)
on May 19, 2010 at 18:46 UTC ( #840763=scratchpad: print w/ replies, xml ) Need Help??

For BrowserUk:

Rate str2time split_nocheck BrowserUk2 BrowserUk + inline_c str2time 16534/s -- -87% -93% -93% + -97% split_nocheck 127292/s 670% -- -44% -45% + -74% BrowserUk2 227574/s 1276% 79% -- -2% + -53% BrowserUk 231067/s 1297% 82% 2% -- + -52% inline_c 485678/s 2837% 282% 113% 110% + --

use Benchmark qw/cmpthese/; use Date::Parse; # str2time use Time::Local qw/timegm_nocheck/; my %mon; @mon{qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/} = 0..11; # For BrowserUk's sub use constant MONTHS => { qw[ Jan 0 Feb 31 Mar 59 Apr 90 May 120 Jun 151 Jul 181 Aug 212 Sep 242 Oct 272 Nov 303 Dec 334 ] }; use Inline C => q@ int epoch_sec(char * date) { char *tz_str = date + 26; struct tm tm; int tz; if ( strlen(date) != 31 || strptime(date, "%a, %d %b %Y %T", &tm) == NULL || sscanf(tz_str, "%d", &tz) != 1) { printf("Invalid date %s\n", date); return 0; } return timegm(&tm) - (tz < 0 ? -1 : 1)*(abs(tz)/100*3600 + abs(tz)%100*60); } @; our $date = "Fri, 01 Mar 2013 01:21:14 +0200"; cmpthese(-3, { str2time => sub { str2time($date) }, # split_nocheck => sub { # my (undef, $dd, $Mm, $yyyy, $hh, $mm, $ss, $tz) # = split /[ ,:]+/o, $date; # timegm_nocheck($ss, $mm, $hh, $dd, $mon{$Mm}, $yyyy) # - ($tz < 0 ? -1 : 1)*(substr($tz,1,2)*3600 + substr($ +tz,3)*60) # }, BrowserUk => sub { my( $d, $m, $y, $H, $M, $S, $tz ) = $date =~ m/^.... (\d\d) (...) (\d\d\d\d) (\d\d):(\d\d):(\d\d) ([+-] +\d{4})/ or die "Bad format $date"; my $leaps = int( ($y - 1970) / 4 + 0.5 ); (((($y-1970)*365 +$leaps+MONTHS->{$m}+($d-1))*24 +$H)*60 +$M)* +60 +$S - ($tz < 0 ? -1 : 1)*(substr($tz,1,2)*3600 + substr($tz,3) +*60) }, BrowserUk2 => sub { my( $d, $m, $y, $H, $M, $S, $tzs, $tzh, $tzm ) = $date =~ m[^.... (\d\d) (...) (\d\d\d\d) (\d\d):(\d\d):(\d\d) ([+-] +)(\d\d)(\d\d)] or die "Bad format $date"; my $leaps = int( ($y - 1970) / 4 + 0.5 ); (((($y-1970)*365 +$leaps+MONTHS->{$m}+($d-1))*24 +$H)*60 +$M)* +60 +$S - ($tzs eq '-' ? -1 : 1)*$tzh*3600 + $tzm*60; }, inline_c => sub { epoch_sec($date) }, });
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 contemplating the Monastery: (7)
As of 2014-08-29 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls