Created
April 7, 2013 03:07
-
-
Save mackee/5328731 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 5.016; | |
use warnings; | |
use Benchmark qw/:all/; | |
use File::Temp qw/tempfile/; | |
use Storable qw/nstore retrieve/; | |
use DateTime::Tiny; | |
my $code = sub { | |
my $client = MongoDB::MongoClient->new(host => 'localhost'); | |
my $col = $client->get_database('test')->get_collection('test'); | |
my $id = $col->insert({ time => DateTime::Tiny->now() }); | |
my $data = $col->find({ _id => $id }); | |
}; | |
my $result; | |
for my $name (qw/ mongo-perl-driver mongo-perl-driver-with-mouse mongo-perl-driver-with-moo /) { | |
my ($fh, $fn) = tempfile(); | |
my $pid = fork; | |
if ($pid) { | |
close $fh; | |
wait; | |
} | |
else { | |
eval qq{ | |
use lib qw{$name/blib/lib $name/blib/arch}; | |
}; | |
eval qq{ | |
use MongoDB; | |
}; | |
my $r = timethis(0, $code); | |
nstore $r, $fn; | |
exit; | |
} | |
$result->{$name} = retrieve $fn; | |
} | |
cmpthese($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment