[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/maintenance/benchmarks/ -> bench_delete_truncate.php (source)

   1  <?php
   2  /**
   3   * Benchmark SQL DELETE vs SQL TRUNCATE.
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   * @ingroup Benchmark
  22   */
  23  
  24  require_once  __DIR__ . '/Benchmarker.php';
  25  
  26  /**
  27   * Maintenance script that benchmarks SQL DELETE vs SQL TRUNCATE.
  28   *
  29   * @ingroup Benchmark
  30   */
  31  class BenchmarkDeleteTruncate extends Benchmarker {
  32  	public function __construct() {
  33          parent::__construct();
  34          $this->mDescription = "Benchmarks SQL DELETE vs SQL TRUNCATE.";
  35      }
  36  
  37  	public function execute() {
  38          $dbw = wfGetDB( DB_MASTER );
  39  
  40          $test = $dbw->tableName( 'test' );
  41          $dbw->query( "CREATE TABLE IF NOT EXISTS /*_*/$test (
  42    test_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
  43    text varbinary(255) NOT NULL
  44  );" );
  45  
  46          $this->insertData( $dbw );
  47  
  48          $start = microtime( true );
  49  
  50          $this->delete( $dbw );
  51  
  52          $end = microtime( true );
  53  
  54          echo "Delete: " . sprintf( "%6.3fms", ( $end - $start ) * 1000 );
  55          echo "\r\n";
  56  
  57          $this->insertData( $dbw );
  58  
  59          $start = microtime( true );
  60  
  61          $this->truncate( $dbw );
  62  
  63          $end = microtime( true );
  64  
  65          echo "Truncate: " . sprintf( "%6.3fms", ( $end - $start ) * 1000 );
  66          echo "\r\n";
  67  
  68          $dbw->dropTable( 'test' );
  69      }
  70  
  71      /**
  72       * @param DatabaseBase $dbw
  73       * @return void
  74       */
  75  	private function insertData( $dbw ) {
  76          $range = range( 0, 1024 );
  77          $data = array();
  78          foreach ( $range as $r ) {
  79              $data[] = array( 'text' => $r );
  80          }
  81          $dbw->insert( 'test', $data, __METHOD__ );
  82      }
  83  
  84      /**
  85       * @param DatabaseBase $dbw
  86       * @return void
  87       */
  88  	private function delete( $dbw ) {
  89          $dbw->delete( 'text', '*', __METHOD__ );
  90      }
  91  
  92      /**
  93       * @param DatabaseBase $dbw
  94       * @return void
  95       */
  96  	private function truncate( $dbw ) {
  97          $test = $dbw->tableName( 'test' );
  98          $dbw->query( "TRUNCATE TABLE $test" );
  99      }
 100  }
 101  
 102  $maintClass = "BenchmarkDeleteTruncate";
 103  require_once RUN_MAINTENANCE_IF_MAIN;


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1