Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: High-speed Date Formatting

by fullermd (Priest)
on Jul 12, 2013 at 07:20 UTC ( #1043893=note: print w/ replies, xml ) Need Help??


in reply to *SOLVED* High-speed Date Formatting

If they're all the same format (or possibly a sufficiently small number of formats), you may be able to use strptime. If you can get something that just hits the C func, it may be quite fast (and even if it doesn't, being able to specify a format rather than call a DWIM interpretation function should be faster anyway).

I see a POSIX::strptime that seems like it may thunk straight through to libc's implementation. DateTime::Format::Strptime looks like a perl reimplementation, so may be slower (but probably more portable, if your system's strptime is broken).


Comment on Re: High-speed Date Formatting
Replies are listed 'Best First'.
Re^2: High-speed Date Formatting
by rjt (Deacon) on Jul 12, 2013 at 08:34 UTC

    Great idea! In fact, I had the same one earlier in this thread at least six hours ago. :-) Here's the relevant sub by itself:

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

    Performs about 25 times faster than str2time.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043893]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2015-07-08 06:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls