X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fnormal%2FUtfNormalBench.php;h=bd4cf05d88d2a33c8e96977e990e16e19d424a7d;hb=bd2a78a159ce6d9f7b27fd75d05570228b44c3cb;hp=392ba2bfdfe5e91481b4c5c0ee05e6edd6f91351;hpb=0bfeedd9c277be0c183c5d69d049059f2742d5b5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/normal/UtfNormalBench.php b/includes/normal/UtfNormalBench.php index 392ba2bfdf..bd4cf05d88 100644 --- a/includes/normal/UtfNormalBench.php +++ b/includes/normal/UtfNormalBench.php @@ -3,7 +3,7 @@ * Approximate benchmark for some basic operations. * * Copyright © 2004 Brion Vibber - * 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 @@ -24,7 +24,11 @@ * @ingroup UtfNormal */ -if( isset( $_SERVER['argv'] ) && in_array( '--icu', $_SERVER['argv'] ) ) { +if ( PHP_SAPI != 'cli' ) { + die( "Run me from the command line please.\n" ); +} + +if ( isset( $_SERVER['argv'] ) && in_array( '--icu', $_SERVER['argv'] ) ) { dl( 'php_utfnormal.so' ); } @@ -34,10 +38,6 @@ require_once 'UtfNormal.php'; define( 'BENCH_CYCLES', 5 ); -if( PHP_SAPI != 'cli' ) { - die( "Run me from the command line please.\n" ); -} - $testfiles = array( 'testdata/washington.txt' => 'English text', 'testdata/berlin.txt' => 'German text', @@ -47,7 +47,7 @@ $testfiles = array( ); $normalizer = new UtfNormal; UtfNormal::loadData(); -foreach( $testfiles as $file => $desc ) { +foreach ( $testfiles as $file => $desc ) { benchmarkTest( $normalizer, $file, $desc ); } @@ -67,11 +67,12 @@ function benchmarkTest( &$u, $filename, $desc ) { # 'NFD', 'NFKD', array( 'fastDecompose', 'fastCombiningSort', 'fastCompose' ), # 'quickIsNFC', 'quickIsNFCVerify', - ); - 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,27 +83,29 @@ 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++ ) { + for ( $i = 0; $i < BENCH_CYCLES; $i++ ) { $start = benchTime(); $out = $u->$form( $data, UtfNormal::$utfCanonicalDecomp ); - $deltas[] = (benchTime() - $start); + $deltas[] = ( benchTime() - $start ); } #$delta = (benchTime() - $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; }