From 19a9db65d826da5c56acde0bd6c4ee7ffd0a271f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 3 Jan 2018 15:26:40 -0300 Subject: [PATCH] Bug 19884: Add benchmark script to compare DBIC vs plain SQL --- Koha/Item.pm | 8 ++++++++ bench_dbic_vs_sql.pl | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 bench_dbic_vs_sql.pl diff --git a/Koha/Item.pm b/Koha/Item.pm index bea05f8317..73306f54a2 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -235,6 +235,14 @@ sub current_holds { return Koha::Holds->_new_from_dbic($hold_rs); } +sub unblessed { + my ($self) = @_; + my $itype = $self->effective_itemtype; + my $h = $self->SUPER->unblessed; + $h->{itype} = $itype; + return $h; +} + =head3 type =cut diff --git a/bench_dbic_vs_sql.pl b/bench_dbic_vs_sql.pl new file mode 100644 index 0000000000..89eedfc2ad --- /dev/null +++ b/bench_dbic_vs_sql.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl +use Modern::Perl; +use C4::Context; +use Koha::Database; +use t::lib::Mocks; +use Time::HiRes qw(gettimeofday tv_interval); + +t::lib::Mocks::mock_preference('item-level_itypes', '1'); + +#BEGIN{$ENV{DBIC_TRACE}=1;}; + +my $biblionumbers = C4::Context->dbh->selectcol_arrayref(qq{SELECT biblionumber FROM biblio}); +sub search_unblessed { + my ($biblionumber) = @_; + my $items = []; + my $sth = C4::Context->dbh->prepare(qq{SELECT * FROM items WHERE biblionumber=?}); + $sth->execute($biblionumber); + while (my $item = $sth->fetchrow_hashref) { + push @{$items}, $item; + } + return wantarray ? @{$items} : $items; +} +sub search_dbic { + my ($biblionumber) = @_; + return [Koha::Database->new->schema->resultset('Item')->search( + { biblionumber => $biblionumber }, + { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } + )->all + ]; +} + +my ($t0, $elapsed); +$t0 = [gettimeofday]; +for my $biblionumber (@$biblionumbers ) { + search_unblessed($biblionumber); +} +$elapsed = tv_interval ( $t0, [gettimeofday]); +print "plain SQL=${elapsed}s\n"; + +$t0 = [gettimeofday]; +for my $biblionumber (@$biblionumbers ) { + search_dbic($biblionumber); +} +$elapsed = tv_interval ( $t0, [gettimeofday]); +print "DBIC=${elapsed}s\n"; -- 2.11.0