3 * Approximate benchmark for some basic operations.
5 * Copyright © 2004 Brion Vibber <brion@pobox.com>
6 * http://www.mediawiki.org/
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
27 if( PHP_SAPI
!= 'cli' ) {
28 die( "Run me from the command line please.\n" );
31 if( isset( $_SERVER['argv'] ) && in_array( '--icu', $_SERVER['argv'] ) ) {
32 dl( 'php_utfnormal.so' );
35 require_once 'UtfNormalDefines.php';
36 require_once 'UtfNormalUtil.php';
37 require_once 'UtfNormal.php';
39 define( 'BENCH_CYCLES', 5 );
42 'testdata/washington.txt' => 'English text',
43 'testdata/berlin.txt' => 'German text',
44 'testdata/bulgakov.txt' => 'Russian text',
45 'testdata/tokyo.txt' => 'Japanese text',
46 'testdata/young.txt' => 'Korean text'
48 $normalizer = new UtfNormal
;
49 UtfNormal
::loadData();
50 foreach( $testfiles as $file => $desc ) {
51 benchmarkTest( $normalizer, $file, $desc );
56 function benchmarkTest( &$u, $filename, $desc ) {
57 print "Testing $filename ($desc)...\n";
58 $data = file_get_contents( $filename );
68 array( 'fastDecompose', 'fastCombiningSort', 'fastCompose' ),
69 # 'quickIsNFC', 'quickIsNFCVerify',
71 foreach( $forms as $form ) {
72 if( is_array( $form ) ) {
74 foreach( $form as $step ) {
75 $str = benchmarkForm( $u, $str, $step );
78 benchmarkForm( $u, $data, $form );
83 function benchTime() {
84 $st = explode( ' ', microtime() );
85 return (float)$st[0] +
(float)$st[1];
88 function benchmarkForm( &$u, &$data, $form ) {
89 #$start = benchTime();
90 for( $i = 0; $i < BENCH_CYCLES
; $i++
) {
92 $out = $u->$form( $data, UtfNormal
::$utfCanonicalDecomp );
93 $deltas[] = (benchTime() - $start);
95 #$delta = (benchTime() - $start) / BENCH_CYCLES;
97 $delta = $deltas[0]; # Take shortest time
99 $rate = intval( strlen( $data ) / $delta );
100 $same = (0 == strcmp( $data, $out ) );
102 printf( " %20s %6.1fms %12s bytes/s (%s)\n",
105 number_format( $rate ),
106 ($same ?
'no change' : 'changed' ) );