Skip to content

Instantly share code, notes, and snippets.

@SpringMT
Created September 23, 2013 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpringMT/6676626 to your computer and use it in GitHub Desktop.
Save SpringMT/6676626 to your computer and use it in GitHub Desktop.
benchmark script
#!/usr/bin/perl
use strict;
use warnings;
use Carp;
use lib 'lib';
use DBI;
use Data::Dumper;
use Benchmark qw(:all);
use DBIx::InsertMultiTranslator qw/intercept/;
my $dbh = DBI->connect('DBI:mysql:hoge:localhost', 'root', '', {'RaiseError' =>1} );
my $sth = $dbh->prepare(qq{INSERT INTO test (id) VALUES (?)});
my $count = 100;
my $r = timethese($count, {'for' => '&test1;', 'multi' => '&test2;'});
cmpthese $r;
sub test1 {
for (my $i = 0; $i < 100; $i++) {
$sth->execute($i);
}
}
sub test2 {
intercept {
for (my $i = 0; $i < 100; $i++) {
$sth->execute($i);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment