From: Peter Rabbitson Date: Sat, 20 Mar 2010 08:41:30 +0000 (+0000) Subject: MOAR bench X-Git-Tag: v0.08121~49 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5f9c6cdae0efaa18b133717ca5549f4c97f9c3b9;p=dbsrgits%2FDBIx-Class.git MOAR bench --- diff --git a/maint/benchmark_datafetch.pl b/maint/benchmark_datafetch.pl index f42d79e..94cb8ea 100755 --- a/maint/benchmark_datafetch.pl +++ b/maint/benchmark_datafetch.pl @@ -3,23 +3,36 @@ use strict; use warnings; +use Benchmark qw/cmpthese/; use FindBin; use lib "$FindBin::Bin/../t/lib"; use lib "$FindBin::Bin/../lib"; -use DBICTest; +use DBICTest::Schema; use DBIx::Class::ResultClass::HashRefInflator; # older dbic didn't load it printf "Benchmarking DBIC version %s\n", DBIx::Class->VERSION; -my $schema = DBICTest->init_schema(); +my $schema = DBICTest::Schema->connect ('dbi:SQLite::memory:'); +$schema->deploy; + my $rs = $schema->resultset ('Artist'); $rs->populate ([ map { { name => "Art_$_"} } (1 .. 10000) ]); -use Benchmark qw/cmpthese/; +my $dbh = $schema->storage->dbh; +my $sql = sprintf ('SELECT %s FROM %s %s', + join (',', @{$rs->_resolved_attrs->{select}} ), + $rs->result_source->name, + $rs->_resolved_attrs->{alias}, +); + +my $compdbi = sub { + my @r = $schema->storage->dbh->selectall_arrayref ('SELECT * FROM ' . ${$rs->as_query}->[0] ) +} if $rs->can ('as_query'); -cmpthese(-5, { - 'Cursor' => sub { $rs->reset; my @r = $rs->cursor->all }, - 'HRI' => sub { $rs->reset; my @r = $rs->search ({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } )->all }, - 'RowObj' => sub { $rs->reset; my @r = $rs->all }, - 'DBI' => sub { my @r = $schema->storage->_get_dbh->selectall_arrayref ('SELECT * FROM ' . ${$rs->as_query}->[0] ) }, +cmpthese(-3, { + Cursor => sub { $rs->reset; my @r = $rs->cursor->all }, + HRI => sub { $rs->reset; my @r = $rs->search ({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } )->all }, + RowObj => sub { $rs->reset; my @r = $rs->all }, + RawDBI => sub { my @r = $dbh->selectall_arrayref ($sql) }, + $compdbi ? (CompDBI => $compdbi) : (), });