From 64e731e466f12c3e79b201b5721b37ceec999d15 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Thu, 15 Dec 2016 18:35:13 +0200 Subject: [PATCH] Bug 17783: Test to print performance of get_effective_issuing_rule This test prints the amount of issuing rule matches per second for 1. worst case, when non-existent branchcode, categorycode and itemtype is being searched (currently 8 queries) 2. mid case (rule found on 4th query) 3. 2nd best case (rule found on 2nd query) 4. best case, when an issuing rule is defined for exactly those branchcode, categorycode and itemtype (currently 1 query) To test: 1. Run t/db_dependent/Koha/IssuingRules.t 2. Write down the per-second amount to compare with next patch Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- t/db_dependent/Koha/IssuingRules.t | 53 +++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/IssuingRules.t b/t/db_dependent/Koha/IssuingRules.t index 1d48fff..158e3cf 100644 --- a/t/db_dependent/Koha/IssuingRules.t +++ b/t/db_dependent/Koha/IssuingRules.t @@ -21,6 +21,8 @@ use Modern::Perl; use Test::More tests => 1; +use Benchmark; + use Koha::IssuingRules; use t::lib::TestBuilder; @@ -31,7 +33,7 @@ $schema->storage->txn_begin; my $builder = t::lib::TestBuilder->new; subtest 'get_effective_issuing_rule' => sub { - plan tests => 1; + plan tests => 2; my $patron = $builder->build({ source => 'Borrower' }); my $item = $builder->build({ source => 'Item' }); @@ -158,6 +160,55 @@ subtest 'get_effective_issuing_rule' => sub { ok(_row_match($rule, $branchcode, $categorycode, $itemtype), 'When I attempt to get effective issuing rule,' .' then the above one is returned.'); }; + + subtest 'Performance' => sub { + plan tests => 4; + + my $worst_case = timethis(500, + sub { Koha::IssuingRules->get_effective_issuing_rule({ + branchcode => 'nonexistent', + categorycode => 'nonexistent', + itemtype => 'nonexistent', + }); + } + ); + my $mid_case = timethis(500, + sub { Koha::IssuingRules->get_effective_issuing_rule({ + branchcode => $branchcode, + categorycode => 'nonexistent', + itemtype => 'nonexistent', + }); + } + ); + my $sec_best_case = timethis(500, + sub { Koha::IssuingRules->get_effective_issuing_rule({ + branchcode => $branchcode, + categorycode => $categorycode, + itemtype => 'nonexistent', + }); + } + ); + my $best_case = timethis(500, + sub { Koha::IssuingRules->get_effective_issuing_rule({ + branchcode => $branchcode, + categorycode => $categorycode, + itemtype => $itemtype, + }); + } + ); + ok($worst_case, 'In worst case, get_effective_issuing_rule finds matching' + .' rule '.sprintf('%.2f', $worst_case->iters/$worst_case->cpu_a) + .' times per second.'); + ok($mid_case, 'In mid case, get_effective_issuing_rule finds matching' + .' rule '.sprintf('%.2f', $mid_case->iters/$mid_case->cpu_a) + .' times per second.'); + ok($sec_best_case, 'In second best case, get_effective_issuing_rule finds matching' + .' rule '.sprintf('%.2f', $sec_best_case->iters/$sec_best_case->cpu_a) + .' times per second.'); + ok($best_case, 'In best case, get_effective_issuing_rule finds matching' + .' rule '.sprintf('%.2f', $best_case->iters/$best_case->cpu_a) + .' times per second.'); + }; }; sub _row_match { -- 2.9.3