Created
September 7, 2014 02:30
-
-
Save bokutin/1af81b8bd1b0ec5524ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Modern::Perl; | |
use Data::Dumper; | |
use Data::Section::Simple qw(get_data_section); | |
use File::Temp; | |
use Text::Outdent qw(outdent); | |
my $sections = get_data_section; | |
for my $name (sort keys %$sections) { | |
my $tmp = File::Temp->new; | |
$tmp->print( outdent $sections->{$name} ); | |
$tmp->close; | |
chmod 0755, $tmp->filename; | |
say "--> $name"; | |
system($tmp->filename); | |
} | |
__DATA__ | |
@@ perl_timepiece | |
#!/usr/bin/env perl | |
use Modern::Perl; | |
use Timer::Simple; | |
use Time::Piece; | |
my $timer = Timer::Simple->new(start => 0, string => 'rps'); | |
$timer->start; | |
for (1..10) { | |
my $t = Time::Piece->strptime('2001-01-01', '%Y-%m-%d'); | |
for (1..10000) { | |
$t = $t->add_months(1); | |
} | |
} | |
$timer->stop; | |
say $timer->string; | |
@@ perl_datetime | |
#!/usr/bin/env perl | |
use Modern::Perl; | |
use Timer::Simple; | |
use DateTime; | |
my $timer = Timer::Simple->new(start => 0, string => 'rps'); | |
$timer->start; | |
for (1..10) { | |
my $t = DateTime->new( year => 2001, month => 1, day => 1 ); | |
for (1..10000) { | |
$t->add( months => 1 ); | |
} | |
} | |
$timer->stop; | |
say $timer->string; | |
@@ perl_timemoment | |
#!/usr/bin/env perl | |
use Modern::Perl; | |
use Timer::Simple; | |
use Time::Moment; | |
my $timer = Timer::Simple->new(start => 0, string => 'rps'); | |
$timer->start; | |
for (1..10) { | |
my $t = Time::Moment->from_string('2001-01-01T00:00:00Z'); | |
for (1..10000) { | |
$t = $t->plus_months(1); | |
} | |
} | |
$timer->stop; | |
say $timer->string; | |
@@ python_monthdelta | |
#!/usr/bin/env python | |
import time | |
from datetime import date, datetime, timedelta | |
from monthdelta import monthdelta | |
t1 = time.time() | |
dd = monthdelta(1) | |
for x in range(0, 10): | |
d1 = datetime(2001, 1, 1) | |
for i in range(0, 10000): | |
d1 += dd | |
t2 = time.time() | |
elapsed = t2 - t1 | |
print "%f" % (elapsed) | |
__END__ | |
% sketch/try_add_months.pl | |
--> perl_datetime | |
27.821845s (0.036/s) | |
--> perl_timemoment | |
0.064609s (15.478/s) | |
--> perl_timepiece | |
1.228693s (0.814/s) | |
--> python_monthdelta | |
0.597144 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment