diff options
-rw-r--r-- | autoload.php | 1 | ||||
-rw-r--r-- | includes/Settings/Config/NullIniSink.php | 21 | ||||
-rw-r--r-- | maintenance/benchmarks/benchmarkSettings.php | 105 |
3 files changed, 127 insertions, 0 deletions
diff --git a/autoload.php b/autoload.php index 5f10674190c9..f180ebea4ca9 100644 --- a/autoload.php +++ b/autoload.php @@ -191,6 +191,7 @@ $wgAutoloadLocalClasses = [ 'BenchmarkParse' => __DIR__ . '/maintenance/benchmarks/benchmarkParse.php', 'BenchmarkPurge' => __DIR__ . '/maintenance/benchmarks/benchmarkPurge.php', 'BenchmarkSanitizer' => __DIR__ . '/maintenance/benchmarks/benchmarkSanitizer.php', + 'BenchmarkSettings' => __DIR__ . '/maintenance/benchmarks/benchmarkSettings.php', 'BenchmarkTidy' => __DIR__ . '/maintenance/benchmarks/benchmarkTidy.php', 'BenchmarkTitleValue' => __DIR__ . '/maintenance/benchmarks/benchmarkTitleValue.php', 'BenchmarkTruncate' => __DIR__ . '/maintenance/benchmarks/benchmarkTruncate.php', diff --git a/includes/Settings/Config/NullIniSink.php b/includes/Settings/Config/NullIniSink.php new file mode 100644 index 000000000000..998f4b674a57 --- /dev/null +++ b/includes/Settings/Config/NullIniSink.php @@ -0,0 +1,21 @@ +<?php + +namespace MediaWiki\Settings\Config; + +/** + * Null implementation of PhpIniSink, useful for testing and benchmarking. + * + * @unstable + */ +class NullIniSink extends PhpIniSink { + + /** + * @param string $option + * @param string $value + * @return void + */ + public function set( string $option, string $value ): void { + // noop + } + +} diff --git a/maintenance/benchmarks/benchmarkSettings.php b/maintenance/benchmarks/benchmarkSettings.php new file mode 100644 index 000000000000..24f7e5fb7199 --- /dev/null +++ b/maintenance/benchmarks/benchmarkSettings.php @@ -0,0 +1,105 @@ +<?php +/** + * Benchmark %MediaWiki hooks. + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Benchmark + */ + +use MediaWiki\MainConfigSchema; +use MediaWiki\Settings\Config\ArrayConfigBuilder; +use MediaWiki\Settings\Config\NullIniSink; +use MediaWiki\Settings\SettingsBuilder; +use MediaWiki\Settings\Source\PhpSettingsSource; +use MediaWiki\Settings\Source\ReflectionSchemaSource; + +require_once __DIR__ . '/../includes/Benchmarker.php'; + +/** + * Maintenance script that benchmarks loading of settings files. + * + * @ingroup Benchmark + */ +class BenchmarkSettings extends Benchmarker { + public function __construct() { + parent::__construct(); + $this->defaultCount = 100; + $this->addDescription( 'Benchmark loading settings files.' ); + } + + private function newSettingsBuilder() { + $extReg = new ExtensionRegistry(); + $configBuilder = new ArrayConfigBuilder(); + $phpIniSink = new NullIniSink(); + return new SettingsBuilder( MW_INSTALL_PATH, $extReg, $configBuilder, $phpIniSink, null ); + } + + public function execute() { + $benches = []; + + $benches['DefaultSettings.php'] = [ + 'setup' => static function () { + // do this once beforehand + include MW_INSTALL_PATH . '/includes/DefaultSettings.php'; + }, + 'function' => static function () { + include MW_INSTALL_PATH . '/includes/DefaultSettings.php'; + } + ]; + + $benches['DefaultSettings.php + config-merge-strategies.php'] = [ + 'setup' => static function () { + // do this once beforehand + include MW_INSTALL_PATH . '/includes/DefaultSettings.php'; + }, + 'function' => function () { + include MW_INSTALL_PATH . '/includes/DefaultSettings.php'; + $settingsBuilder = $this->newSettingsBuilder(); + $settingsBuilder->load( + new PhpSettingsSource( + MW_INSTALL_PATH . '/includes/config-merge-strategies.php' + ) + ); + $settingsBuilder->apply(); + } + ]; + + $benches['config-schema.php'] = [ + 'function' => function () { + $settingsBuilder = $this->newSettingsBuilder(); + $settingsBuilder->load( + new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' ) + ); + $settingsBuilder->apply(); + } + ]; + + $benches['MainConfigSchema::class'] = [ + 'function' => function () { + $settingsBuilder = $this->newSettingsBuilder(); + $settingsBuilder->load( new ReflectionSchemaSource( MainConfigSchema::class ) ); + $settingsBuilder->apply(); + } + ]; + + $this->bench( $benches ); + } +} + +$maintClass = BenchmarkSettings::class; +require_once RUN_MAINTENANCE_IF_MAIN; |