X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2Fbenchmarks%2Fbench_delete_truncate.php;h=0a999ecca1a9d0dcee5291b7ff7c7ae5a1df69df;hb=13e7350c74368cddae3bcca90e6ad281b08ef0d6;hp=2a8d79a944200cb188f4e7a27b96e7729c75938e;hpb=12313956c58e88b98d4baf722464e09b4a351bf3;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/benchmarks/bench_delete_truncate.php b/maintenance/benchmarks/bench_delete_truncate.php index 2a8d79a944..0a999ecca1 100644 --- a/maintenance/benchmarks/bench_delete_truncate.php +++ b/maintenance/benchmarks/bench_delete_truncate.php @@ -23,12 +23,17 @@ require_once __DIR__ . '/Benchmarker.php'; +use Wikimedia\Rdbms\IDatabase; +use Wikimedia\Rdbms\IMaintainableDatabase; + /** * Maintenance script that benchmarks SQL DELETE vs SQL TRUNCATE. * * @ingroup Benchmark */ class BenchmarkDeleteTruncate extends Benchmarker { + protected $defaultCount = 10; + public function __construct() { parent::__construct(); $this->addDescription( 'Benchmarks SQL DELETE vs SQL TRUNCATE.' ); @@ -43,33 +48,30 @@ class BenchmarkDeleteTruncate extends Benchmarker { text varbinary(255) NOT NULL );" ); - $this->insertData( $dbw ); - - $start = microtime( true ); - - $this->delete( $dbw ); - - $end = microtime( true ); - - echo "Delete: " . sprintf( "%6.3fms", ( $end - $start ) * 1000 ); - echo "\r\n"; - - $this->insertData( $dbw ); - - $start = microtime( true ); - - $this->truncate( $dbw ); - - $end = microtime( true ); - - echo "Truncate: " . sprintf( "%6.3fms", ( $end - $start ) * 1000 ); - echo "\r\n"; + $this->bench( [ + 'Delete' => [ + 'setup' => function () use ( $dbw ) { + $this->insertData( $dbw ); + }, + 'function' => function () use ( $dbw ) { + $this->delete( $dbw ); + } + ], + 'Truncate' => [ + 'setup' => function () use ( $dbw ) { + $this->insertData( $dbw ); + }, + 'function' => function () use ( $dbw ) { + $this->truncate( $dbw ); + } + ] + ] ); $dbw->dropTable( 'test' ); } /** - * @param Database $dbw + * @param IDatabase $dbw * @return void */ private function insertData( $dbw ) { @@ -82,7 +84,7 @@ class BenchmarkDeleteTruncate extends Benchmarker { } /** - * @param Database $dbw + * @param IDatabase $dbw * @return void */ private function delete( $dbw ) { @@ -90,7 +92,7 @@ class BenchmarkDeleteTruncate extends Benchmarker { } /** - * @param Database $dbw + * @param IMaintainableDatabase $dbw * @return void */ private function truncate( $dbw ) { @@ -99,5 +101,5 @@ class BenchmarkDeleteTruncate extends Benchmarker { } } -$maintClass = "BenchmarkDeleteTruncate"; +$maintClass = 'BenchmarkDeleteTruncate'; require_once RUN_MAINTENANCE_IF_MAIN;