From 60ef96960f262a98b80dfb586e967dda911a977c Mon Sep 17 00:00:00 2001 From: Jacek Ablewicz Date: Fri, 8 Jul 2016 11:42:48 +0200 Subject: [PATCH] Bug 16076 - DBIx searches - performance issues Quick & dirty test script for benchmarking database search performance using various DBI and DBIx approaches. --- .../_dbix_test_search_performance_all_sysprefs.pl | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 misc/tests/_dbix_test_search_performance_all_sysprefs.pl diff --git a/misc/tests/_dbix_test_search_performance_all_sysprefs.pl b/misc/tests/_dbix_test_search_performance_all_sysprefs.pl new file mode 100755 index 0000000..02f2f2a --- /dev/null +++ b/misc/tests/_dbix_test_search_performance_all_sysprefs.pl @@ -0,0 +1,56 @@ +#!/usr/bin/perl + +use Modern::Perl; +use Koha::Config::SysPrefs; + +my $results; + +for (1..1000) { + $results = sysprefs_from_mysql(); ## 1.82 msec + ## $results = sysprefs_dbix_hashref_inflator(); ## 12.5 msec + ## $results = sysprefs_dbix_unblessed(); ## 17.6 msec + + ## Note: numbers above are results for current master (08/07/2016) + ## on Wheezy (DBIx::Class version 0.08196), i7-3770 CPU @ 3.40GHz. + ## + ## For 3.22.x on Jessie (DBIx 0.082810, i7-930 CPU @ 2.80GHz) + ## there is a huge difference: + ## + ## $results = sysprefs_from_mysql(); ## 2.52 msec + ## $results = sysprefs_dbix_hashref_inflator(); ## 3.51 msec + ## $results = sysprefs_dbix_unblessed(); ## 7.9 msec + ## + ## DBIx search with DBIx::Class::ResultClass::HashRefInflator + ## attribute is (almost) as fast as plain DBI search. +} + +print "Got ".scalar(@$results)." sysprefs\n"; + +sub sysprefs_dbix_unblessed { + my $all_prefs = Koha::Config::SysPrefs->search( + undef, + { columns => [qw/value variable/] } + )->unblessed(); + + $all_prefs; +} + +sub sysprefs_dbix_hashref_inflator { + my $all_prefs = Koha::Config::SysPrefs->search_all_unblessed( + undef, + { columns => [qw/value variable/] } + ); + + $all_prefs; +} + +sub sysprefs_from_mysql { + my $dbh = C4::Context->dbh(); + my $sql = 'SELECT variable, value FROM systempreferences'; + + my $sth = $dbh->prepare($sql); + $sth->execute; + my $result = $sth->fetchall_arrayref({}); + + $result; +} -- 1.7.10.4