From 174f45fd4ab35224225c754b083f7fa413231629 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 12 Jun 2020 12:40:39 +0100 Subject: [PATCH] Bug 25723: [DO NOT PUSH] Benchmark Script A quick benchmark to compare DateTime::Set->contains to a simple hashref lookup Signed-off-by: Nick Clemens --- misc/devel/benchmark_calendar.pl | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 misc/devel/benchmark_calendar.pl diff --git a/misc/devel/benchmark_calendar.pl b/misc/devel/benchmark_calendar.pl new file mode 100644 index 0000000000..29b8a13630 --- /dev/null +++ b/misc/devel/benchmark_calendar.pl @@ -0,0 +1,62 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Copyright 2016 Koha Development Team +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use Benchmark; + +use DateTime; +use DateTime::Set; +use DateTime::Event::Random; + +my $start = DateTime->new( year => 2020, month => 3 ); +my $end = DateTime->new( year => 2020, month => 5 ); +my $set = DateTime::Event::Random->new_cached( + days => 5, + start => $start, + end => $end +); + +my $exception_holidays = {}; +my $iter = $set->iterator; +while ( my $dt = $iter->next ) { + $exception_holidays->{ $dt->ymd('') } = 1; +} + +my $test_datetime = + DateTime::Event::Random->datetime( start => $start, end => $end ); +my $test_datestring = $test_datetime->ymd(''); + +my $time_set = sub { + return $set->contains($test_datetime); + +}; + +my $time_hash = sub { + return 1 if ( $exception_holidays->{$test_datestring} ); + return 0; + +}; + +Benchmark::cmpthese( + -10, + { + 'DateTime::Set' => $time_set, + 'hashref' => $time_hash, + } +); -- 2.11.0