Physikerwelt has uploaded a new change for review.
https://gerrit.wikimedia.org/r/257885
Change subject: Actual performance tests
......................................................................
Actual performance tests
* Tests for the new restbase rendering
Change-Id: I739e79ba31b5882b6d535744ee6359949e6c4898
---
M maintenance/MathPerformance.php
1 file changed, 112 insertions(+), 58 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MathSearch
refs/changes/85/257885/1
diff --git a/maintenance/MathPerformance.php b/maintenance/MathPerformance.php
index cbdb770..4d297b2 100644
--- a/maintenance/MathPerformance.php
+++ b/maintenance/MathPerformance.php
@@ -19,18 +19,18 @@
* @ingroup Maintenance
*/
-require_once ( __DIR__ . '/../../../maintenance/Maintenance.php' );
+require_once( __DIR__ . '/../../../maintenance/Maintenance.php' );
+
class MathPerformance extends Maintenance {
const RTI_CHUNK_SIZE = 10000;
public $purge = false;
+ /** @var DatabaseBase */
+ public $dbw;
/** @var boolean */
private $verbose;
/** @var DatabaseBase */
- public $dbw;
- /** @var DatabaseBase */
private $db;
- /** @var MathRenderer */
- private $current;
+ private $currentHash;
private $time = 0.0; // microtime( true );
private $performance = array();
private $renderingMode = 'mathml';
@@ -51,6 +51,97 @@
false, 'v' );
}
+ public function execute() {
+ global $wgMathValidModes;
+ $this->dbw = wfGetDB( DB_MASTER );
+ $this->db = wfGetDB( DB_MASTER );
+ $wgMathValidModes[] = $this->renderingMode;
+ $this->verbose = $this->getOption( 'verbose', false );
+ $this->vPrint( "Loaded." );
+ $action = trim( $this->getArg( 0, 'export' ) );
+ switch ( $action ) {
+ case 'export':
+ $this->actionExport();
+ break;
+ case "benchmark":
+ $this->actionBenchmark();
+ break;
+ }
+ $this->vPrint( "Done." );
+ }
+
+ private function actionExport() {
+ $tex = $this->getOption( 'input', 'math_input' );
+ $hash = $this->getOption( 'hash', 'math_inputhash' );
+ $formulae = $this->getFormulae( $hash, $tex );
+ $out = array();
+ foreach ( $formulae as $formula ) {
+ $out[] = array( $hash => base64_encode( $formula->$hash
), $tex => $formula->$tex );
+ }
+ $output = $this->getOption( 'output', 'php://stdout' );
+ file_put_contents( $output, json_encode( $out,
JSON_PRETTY_PRINT ) );
+ }
+
+ /**
+ * @param $hash
+ * @param $tex
+ * @return bool|ResultWrapper
+ * @throws DBUnexpectedError
+ */
+ private function getFormulae( $hash, $tex ) {
+ $min = $this->getOption( 'min', 0 );
+ $max = $this->getOption( 'max', 0 );
+ $options = array();
+ if ( $max ) {
+ $options['LIMIT'] = $max - $min;
+ $options['OFFSET'] = $min;
+ }
+ $table = $this->getOption( 'table', 'mathoid' );
+ $shares = $this->getArg( 1, false ); // 'shares'
+ $share = $this->getArg( 2, 0 ); // 'share'
+ if ( $shares ) {
+ $this->vPrint( "Processing share $share of $shares." );
+ $counts = $this->db->selectField( $table, 'count(*)' );
+ $bucket = ceil( $counts / $shares );
+ $min = $share * $bucket;
+ $max = $min + $bucket;
+ $options['LIMIT'] = $max - $min;
+ $options['OFFSET'] = $min;
+ }
+ $formulae = $this->db->select(
+ $table,
+ array( $hash, $tex ),
+ '',
+ __METHOD__,
+ $options
+ );
+ return $formulae;
+ }
+
+ private function actionBenchmark() {
+ $tex = $this->getOption( 'input', 'math_input' );
+ $hash = $this->getOption( 'hash', 'math_inputhash' );
+ $formulae = $this->getFormulae( $hash, $tex );
+ foreach ( $formulae as $formula ) {
+ $this->currentHash = $formula->$hash;
+ $rbi = new MathRestbaseInterface( $formula->$tex, false
);
+ $this->resetTimer();
+ $rbi->checkTeX();
+ $this->time( 'check' );
+ if ( round( rand( 0, 1 ) ) ) {
+ $rbi->getSvg();
+ $this->time( '1-svg' );
+ $rbi->getMathML();
+ $this->time( '2-mathml' );
+ } else {
+ $rbi->getMathML();
+ $this->time( '1-mathml' );
+ $rbi->getSvg();
+ $this->time( '2-svg' );
+ }
+ }
+ }
+
/**
* Measures time in ms.
* In order to have a formula centric evaluation, we can not just the
build in profiler
@@ -66,70 +157,33 @@
} else {
$this->performance[$category] = $delta;
}
+ $logData = array(
+ 'math_inputhash' => $this->currentHash,
+ 'mathperformance_name' => substr( $category, 0, 10 ),
+ 'mathperformance_time' => $delta,
+ 'mathperformance_mode' => MathHooks::mathModeToHashKey(
$this->renderingMode )
+ );
if ( $wgMathDebug ) {
- $this->db->insert( 'mathperformance', array(
- 'math_inputhash' =>
$this->current->getInputHash(),
- 'mathperformance_name' => substr( $category, 0,
10 ),
- 'mathperformance_time' => $delta,
- 'mathperformance_mode' =>
MathHooks::mathModeToHashKey( $this->renderingMode )
- ) );
+ $this->db->insert( 'mathperformance', $logData );
+ } else {
+ $logData['math_inputhash'] = base64_encode(
$logData['math_inputhash'] );
+ echo json_encode( $logData ) . "\n";
}
- $this->time = microtime( true );
-
+ $this->resetTimer();
return (int)$delta;
}
-
- public function execute() {
- global $wgMathValidModes;
- $this->dbw = wfGetDB( DB_MASTER );
- $this->db = wfGetDB( DB_MASTER );
- $wgMathValidModes[] = $this->renderingMode;
- $this->output( "Loaded.\n" );
+ private function resetTimer() {
$this->time = microtime( true );
- if ( $this->getArg( 0, 'export' ) == 'export' ) {
- $this->renderFromTable();
- }
}
- private function renderFromTable() {
- $min = $this->getOption( 'min', 0 );
- $max = $this->getOption( 'max', 0 );
- $options = array();
- if ( $max ) {
- $options['LIMIT'] = $max - $min;
- $options['OFFSET'] = $min;
+ private function vPrint( $string ) {
+ if ( $this->verbose ) {
+ $this->output( $string . "\n" );
}
- $table = $this->getOption( 'table', 'mathoid' );
- $tex = $this->getOption( 'input', 'math_input' );
- $hash = $this->getOption( 'hash', 'math_inputhash' );
- $shares = $this->getArg( 1, false ); // 'shares'
- $share = $this->getArg( 2, 0 ); // 'share'
- if ( $shares ) {
- // echo "I'm share $share of $shares";
- $counts = $this->db->selectField( $table, 'count(*)' );
- $bucket = ceil( $counts / $shares );
- $min = $share * $bucket;
- $max = $min + $bucket;
- $options['LIMIT'] = $max - $min;
- $options['OFFSET'] = $min;
- }
- $formulae = $this->db->select(
- $table,
- array( $hash, $tex ),
- '',
- __METHOD__,
- $options
- );
- $out = array();
- foreach ( $formulae as $formula ) {
- $out[] = array( $hash => base64_encode( $formula->$hash
), $tex => $formula->$tex );
- }
- $output = $this->getOption( 'output', 'php://stdout' );
- file_put_contents( $output, json_encode( $out,
JSON_PRETTY_PRINT ) );
}
}
$maintClass = "MathPerformance";
/** @noinspection PhpIncludeInspection */
-require_once ( RUN_MAINTENANCE_IF_MAIN );
+require_once( RUN_MAINTENANCE_IF_MAIN );
--
To view, visit https://gerrit.wikimedia.org/r/257885
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I739e79ba31b5882b6d535744ee6359949e6c4898
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MathSearch
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits