Time::Piece

vek on 2002-03-07T06:06:14

Cheers matts, saved me a code re-write. A former co-worker of mine wrote an in-house module years ago that does almost everything Time::Piece does. Except that it's sloooow, really slooow. I've been wanting to re-write the damn thing for ages, it uses Date::Manip which I think is the offending beast. I never got around to the re-write of course and faced the "opinions" of those higher up on the totem pole at work, yeh but our in-house module just works, if it aint broke don't fix it. So, tonight I wrote some benchmark code, just had both modules calc today's date in YYYYMMDD format (20000 iterations): Benchmark: timing 20000 iterations of Time::Piece, DateAndTime.pm... Time::Piece: 7 wallclock secs ( 6.68 usr + 0.39 sys = 7.07 CPU) @ 2828.85/s (n=20000) DateAndTime.pm: 168 wallclock secs (162.68 usr 0.03 sys + 0.00 cusr 0.02 csys = 162.73 CPU) @ 122.92/s (n=20000) 'kay, I think I'll use Time::Piece thanks...


Date::Manip

pudge on 2002-03-07T14:45:24

FWIW, from Date/Manip.pod:

The downside is that Date::Manip is slow, especially when compared to several of the other Date/Time modules which are written in C. Although I am working on making Date::Manip faster, it will never be as fast as these modules. And before anyone asks, Date::Manip will never be translated to C (at least by me). I write C because I have to. I write perl because I like to. Date::Manip is something I do because it interests me, not something I'm paid for.

Yes, Date::Manip is VERY SLOW. Don't use it unless you want to be slow, or need something only Date::Manip provides.

Time::Piece is my favorite module

jdavidb on 2002-03-08T18:17:16

A design for something identical to this module was etched in red on my whiteboard for the first six months of 2000. (After Dec. 31, 1999 when I fixed a bunch of contract code that was supposed to have been reviewed, and then spent Jan. 3 reviewing it and thinking. Am I the only person who actually read the docs to localtime() the first time he used it?) Of course, I had no time to actually implement the thing. Then one day Time::Object appeared. I was amazed; it was as if Matt had read my mind. (And I snickered at the bug report that launched the comments by Larry that launched the module. Am I the only person who -- oh, never mind.)

Time::{Object,Piece} gets my vote for best module ever. I guarantee the code in that module is executed more often on our servers than any other module in CPAN. Prior to that we had command-line utilities that did date arithmetic on YYMMDD[HH[MM]] timestamps. The utilities were crufty Perl rewrites of a decent original C implementation (C didn't make it from SunOS to Solaris because somebody didn't have the right docs). Prior to that there was actually a set of cron jobs that wrote datestamps for the last n days, hours, etc. into files which people read with backticks. I wrote eponymous Perl functions for all our utilities using Time::Object, and then rewrote the utilities to call the functions. And, thanks to POD, our utilities now have manpages.:)

For the short time when jhi was going to put Time::Piece in core, someone observed that most of the date-related entries in the FAQ could be replaced with "See Time::Piece." :)