Created
June 23, 2009 10:02
-
-
Save hidek/134461 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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