in reply to Timegm and timelocal

I assume you mean gmtime and localtime.

Unless this benchmark is fundamentally flawed, it seems gmtime is 2x faster than localtime. See perlfunc for more.
#!/usr/bin/perl -sw use strict; use Benchmark; our $ITERATIONS ||= 1e7; timethese($ITERATIONS, { gmtime => sub { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime(time); }, localtime => sub { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) += localtime(time); }, } ); __END__ $ perl 619744.pl Benchmark: timing 10000000 iterations of localtime, gmtime... localtime: 101 wallclock secs (51.07 usr + 45.89 sys = 96.96 CPU) @ 1 +03135.31/s (n=10000000) gmtime: 62 wallclock secs (29.76 usr + 27.94 sys = 57.70 CPU) @ 17 +3310.23/s (n=10000000)
#!/usr/bin/perl -sw use strict; use Benchmark; use Time::Local; our $ITERATIONS ||= 1e7; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime(time); timethese($ITERATIONS, { timegm => sub { my $time = timegm($sec,$min,$hour,$mday,$mon, +$year); }, timelocal => sub { my $time = timelocal($sec,$min,$hour,$mday,$m +on,$year); }, } ); __END__ $ perl 619744.pl Benchmark: timing 10000000 iterations of timegm, timelocal... timegm: 95 wallclock secs (89.95 usr + 0.06 sys = 90.01 CPU) @ 11 +1098.77/s (n=10000000) timelocal: 811 wallclock secs (654.30 usr + 112.15 sys = 766.45 CPU) +@ 13047.17/s (n=10000000)
Update: Now comparing Time::Local functions.
--
print map{chr}unpack(q{A3}x24,q{074117115116032097110111116104101114032080101114108032104097099107101114})

Replies are listed 'Best First'.
Re^2: Timegm and timelocal
by Zaxo (Archbishop) on Jun 07, 2007 at 07:55 UTC

    I think OP refers to timegm() and timelocal() from Time::Local.

    After Compline,
    Zaxo