diff options
Diffstat (limited to 'includes/normal/UtfNormalMemStress.php')
-rw-r--r-- | includes/normal/UtfNormalMemStress.php | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/includes/normal/UtfNormalMemStress.php b/includes/normal/UtfNormalMemStress.php index 9732d762..f133e4d5 100644 --- a/includes/normal/UtfNormalMemStress.php +++ b/includes/normal/UtfNormalMemStress.php @@ -5,7 +5,7 @@ * to test regression on mem usage (bug 28146) * * Copyright © 2004-2011 Brion Vibber <brion@wikimedia.org> - * http://www.mediawiki.org/ + * https://www.mediawiki.org/ * * 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 @@ -26,11 +26,11 @@ * @ingroup UtfNormal */ -if( PHP_SAPI != 'cli' ) { +if ( PHP_SAPI != 'cli' ) { die( "Run me from the command line please.\n" ); } -if( isset( $_SERVER['argv'] ) && in_array( '--icu', $_SERVER['argv'] ) ) { +if ( isset( $_SERVER['argv'] ) && in_array( '--icu', $_SERVER['argv'] ) ) { dl( 'php_utfnormal.so' ); } @@ -39,8 +39,8 @@ require_once 'UtfNormalUtil.php'; require_once 'UtfNormal.php'; define( 'BENCH_CYCLES', 1 ); -define( 'BIGSIZE', 1024 * 1024 * 10); // 10m -ini_set('memory_limit', BIGSIZE + 120 * 1024 * 1024); +define( 'BIGSIZE', 1024 * 1024 * 10 ); // 10m +ini_set( 'memory_limit', BIGSIZE + 120 * 1024 * 1024 ); $testfiles = array( 'testdata/washington.txt' => 'English text', @@ -51,7 +51,7 @@ $testfiles = array( ); $normalizer = new UtfNormal; UtfNormal::loadData(); -foreach( $testfiles as $file => $desc ) { +foreach ( $testfiles as $file => $desc ) { benchmarkTest( $normalizer, $file, $desc ); } @@ -61,19 +61,20 @@ function benchmarkTest( &$u, $filename, $desc ) { print "Testing $filename ($desc)...\n"; $data = file_get_contents( $filename ); $all = $data; - while (strlen($all) < BIGSIZE) { + while ( strlen( $all ) < BIGSIZE ) { $all .= $all; } $data = $all; - echo "Data is " . strlen($data) . " bytes.\n"; + echo "Data is " . strlen( $data ) . " bytes.\n"; $forms = array( - 'quickIsNFCVerify', + 'quickIsNFCVerify', 'cleanUp', - ); - foreach( $forms as $form ) { - if( is_array( $form ) ) { + ); + + foreach ( $forms as $form ) { + if ( is_array( $form ) ) { $str = $data; - foreach( $form as $step ) { + foreach ( $form as $step ) { $str = benchmarkForm( $u, $str, $step ); } } else { @@ -82,29 +83,25 @@ function benchmarkTest( &$u, $filename, $desc ) { } } -function benchTime() { - $st = explode( ' ', microtime() ); - return (float)$st[0] + (float)$st[1]; -} - function benchmarkForm( &$u, &$data, $form ) { - #$start = benchTime(); - for( $i = 0; $i < BENCH_CYCLES; $i++ ) { - $start = benchTime(); + #$start = microtime( true ); + for ( $i = 0; $i < BENCH_CYCLES; $i++ ) { + $start = microtime( true ); $out = $u->$form( $data, UtfNormal::$utfCanonicalDecomp ); - $deltas[] = (benchTime() - $start); + $deltas[] = ( microtime( true ) - $start ); } - #$delta = (benchTime() - $start) / BENCH_CYCLES; + #$delta = (microtime( true ) - $start) / BENCH_CYCLES; sort( $deltas ); $delta = $deltas[0]; # Take shortest time $rate = intval( strlen( $data ) / $delta ); - $same = (0 == strcmp( $data, $out ) ); + $same = ( 0 == strcmp( $data, $out ) ); printf( " %20s %6.1fms %12s bytes/s (%s)\n", $form, - $delta*1000.0, + $delta * 1000.0, number_format( $rate ), - ($same ? 'no change' : 'changed' ) ); + ( $same ? 'no change' : 'changed' ) ); + return $out; } |