Skip to content

Instantly share code, notes, and snippets.

@hidek
Created June 23, 2009 10:02
Show Gist options
  • Select an option

  • Save hidek/134461 to your computer and use it in GitHub Desktop.

Select an option

Save hidek/134461 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use DBI;
use Benchmark qw(:all);
my $count = 100;
my $loop = 100;
unlink('test.db');
my $dbh = DBI->connect('dbi:SQLite:dbname=test.db');
$dbh->do(
"CREATE TABLE test (id int not null, name text not null, primary key(id))"
);
$dbh->do('BEGIN');
for (1 .. $loop) {
$dbh->do("INSERT INTO test(id, name) VALUES($_, 'name_$_')");
}
$dbh->do('COMMIT');
cmpthese(
$count,
{
commit_each_select => \&commit_each_select,
commit_bulk_select => \&commit_bulk_select,
}
);
sub commit_each_select {
for (1 .. $loop) {
$dbh->do("SELECT * FROM test WHERE id = $_");
}
}
sub commit_bulk_select {
$dbh->do('BEGIN');
for (1 .. $loop) {
$dbh->do("SELECT * FROM test WHERE id = $_");
}
$dbh->do('COMMIT');
}
Rate commit_each_select commit_bulk_select
commit_each_select 57.8/s -- -17%
commit_bulk_select 69.9/s 21% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment