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/perl | |
use strict; | |
use warnings; | |
use DBI; | |
use File::Temp qw/tempfile/; | |
use Parallel::Benchmark; | |
for my $n ( 1..4 ) { | |
(undef ,my $db) = tempfile(OPEN => 0); | |
my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",{ | |
RaiseError => 1, | |
AutoCommit => 1, | |
sqlite_use_immediate_transaction => 1, | |
}); | |
$dbh->do('create table if not exists foo (id)'); | |
$dbh->do('insert into foo values(?)',{}, 1); | |
my $bm = Parallel::Benchmark->new( | |
setup => sub { | |
my ($self, $id) = @_; | |
$self->stash->{dbh} = DBI->connect("dbi:SQLite:dbname=$db","","",{ | |
RaiseError => 1, | |
AutoCommit => 1, | |
sqlite_use_immediate_transaction => 1, | |
}); | |
$self->stash->{dbh}->do('PRAGMA journal_mode = WAL') if $n > 1; | |
$self->stash->{dbh}->do('PRAGMA synchronous = NORMAL') if $n == 3; | |
$self->stash->{dbh}->do('PRAGMA synchronous = OFF') if $n > 3; | |
}, | |
benchmark => sub { | |
my ($self, $id) = @_; | |
my $dbh = $self->stash->{dbh}; | |
$dbh->begin_work; | |
my $arrayref = $dbh->selectrow_arrayref('select * from foo limit 1;'); | |
$dbh->do('insert into foo values(?)',{}, $arrayref->[0]++); | |
$dbh->commit; | |
return 1; | |
}, | |
teardown => sub { | |
my ($self, $id) = @_; | |
delete $self->stash->{dbh}; | |
}, | |
concurrency => 4, | |
time => 8, | |
); | |
my $result = $bm->run(); | |
} | |
__END__ | |
#default | |
2012-06-08T18:29:58 [INFO] starting benchmark: concurrency: 4, time: 8 | |
2012-06-08T18:30:08 [INFO] done benchmark: score 5560, elapsed 8.082 sec = 687.942 / sec | |
# journal_mode = WAL | |
2012-06-08T18:30:08 [INFO] starting benchmark: concurrency: 4, time: 8 | |
2012-06-08T18:30:18 [INFO] done benchmark: score 16624, elapsed 8.032 sec = 2069.632 / sec | |
# journal_mode = WAL + synchronous = NORMAL | |
2012-06-08T18:30:18 [INFO] starting benchmark: concurrency: 4, time: 8 | |
2012-06-08T18:30:28 [INFO] done benchmark: score 31283, elapsed 8.000 sec = 3910.348 / sec | |
# journal_mode = WAL + synchronous = OFF | |
2012-06-08T18:30:28 [INFO] starting benchmark: concurrency: 4, time: 8 | |
2012-06-08T18:30:38 [INFO] done benchmark: score 33307, elapsed 8.003 sec = 4161.728 / sec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment