From 1031825f3b7732fb03fa745bff12e671c2f73d1a Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 18 Aug 2018 04:29:53 +0100 Subject: [PATCH] benchmarks: Minor cleanup for strtr benchmark Only bench with variable input ("indirect"). The static string is too unrealistic and not worth testing for imho, if it even makes a difference at all. Also bump the default count from 100 to 10,000 given it's so tiny. Change-Id: Iccc35af4bd3c5b0967983ddfacd1d4ead235e4a4 --- autoload.php | 2 +- .../benchmarks/bench_strtr_str_replace.php | 74 ------------------- .../benchmarks/benchmarkStringReplacement.php | 55 ++++++++++++++ 3 files changed, 56 insertions(+), 75 deletions(-) delete mode 100644 maintenance/benchmarks/bench_strtr_str_replace.php create mode 100644 maintenance/benchmarks/benchmarkStringReplacement.php diff --git a/autoload.php b/autoload.php index 999d82dba9..1d6138139c 100644 --- a/autoload.php +++ b/autoload.php @@ -187,7 +187,6 @@ $wgAutoloadLocalClasses = [ 'BcryptPassword' => __DIR__ . '/includes/password/BcryptPassword.php', 'BenchHttpHttps' => __DIR__ . '/maintenance/benchmarks/bench_HTTP_HTTPS.php', 'BenchIfSwitch' => __DIR__ . '/maintenance/benchmarks/bench_if_switch.php', - 'BenchStrtrStrReplace' => __DIR__ . '/maintenance/benchmarks/bench_strtr_str_replace.php', 'BenchUtf8TitleCheck' => __DIR__ . '/maintenance/benchmarks/bench_utf8_title_check.php', 'BenchWfIsWindows' => __DIR__ . '/maintenance/benchmarks/bench_wfIsWindows.php', 'BenchWikimediaBaseConvert' => __DIR__ . '/maintenance/benchmarks/bench_Wikimedia_base_convert.php', @@ -200,6 +199,7 @@ $wgAutoloadLocalClasses = [ 'BenchmarkParse' => __DIR__ . '/maintenance/benchmarks/benchmarkParse.php', 'BenchmarkPurge' => __DIR__ . '/maintenance/benchmarks/benchmarkPurge.php', 'BenchmarkSanitizer' => __DIR__ . '/maintenance/benchmarks/benchmarkSanitizer.php', + 'BenchmarkStringReplacement' => __DIR__ . '/maintenance/benchmarks/benchmarkStringReplacement.php', 'BenchmarkTidy' => __DIR__ . '/maintenance/benchmarks/benchmarkTidy.php', 'BenchmarkTitleValue' => __DIR__ . '/maintenance/benchmarks/benchmarkTitleValue.php', 'Benchmarker' => __DIR__ . '/maintenance/benchmarks/Benchmarker.php', diff --git a/maintenance/benchmarks/bench_strtr_str_replace.php b/maintenance/benchmarks/bench_strtr_str_replace.php deleted file mode 100644 index 2c065f6cc3..0000000000 --- a/maintenance/benchmarks/bench_strtr_str_replace.php +++ /dev/null @@ -1,74 +0,0 @@ -addDescription( 'Benchmark for strtr() vs str_replace().' ); - } - - public function execute() { - $this->bench( [ - [ 'function' => [ $this, 'benchstrtr' ] ], - [ 'function' => [ $this, 'benchstr_replace' ] ], - [ 'function' => [ $this, 'benchstrtr_indirect' ] ], - [ 'function' => [ $this, 'benchstr_replace_indirect' ] ], - ] ); - } - - protected function benchstrtr() { - strtr( "[[MediaWiki:Some_random_test_page]]", "_", " " ); - } - - protected function benchstr_replace() { - str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]" ); - } - - protected function benchstrtr_indirect() { - bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" ); - } - - protected function benchstr_replace_indirect() { - bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" ); - } -} - -$maintClass = BenchStrtrStrReplace::class; -require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/benchmarks/benchmarkStringReplacement.php b/maintenance/benchmarks/benchmarkStringReplacement.php new file mode 100644 index 0000000000..6db024cf3b --- /dev/null +++ b/maintenance/benchmarks/benchmarkStringReplacement.php @@ -0,0 +1,55 @@ +addDescription( 'Benchmark for string replacement methods.' ); + } + + public function execute() { + $this->bench( [ + 'strtr' => [ $this, 'bench_strtr' ], + 'str_replace' => [ $this, 'bench_str_replace' ], + ] ); + } + + protected function bench_strtr() { + strtr( $this->input, "_", " " ); + } + + protected function bench_str_replace() { + str_replace( "_", " ", $this->input ); + } +} + +$maintClass = BenchmarkStringReplacement::class; +require_once RUN_MAINTENANCE_IF_MAIN; -- 2.20.1