[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Approximate benchmark for some basic operations. 4 * 5 * Copyright © 2004 Brion Vibber <[email protected]> 6 * https://www.mediawiki.org/ 7 * 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. 12 * 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. 17 * 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 22 * 23 * @file 24 * @ingroup UtfNormal 25 */ 26 27 if ( PHP_SAPI != 'cli' ) { 28 die( "Run me from the command line please.\n" ); 29 } 30 31 if ( isset( $_SERVER['argv'] ) && in_array( '--icu', $_SERVER['argv'] ) ) { 32 dl( 'php_utfnormal.so' ); 33 } 34 35 require_once 'UtfNormalDefines.php'; 36 require_once 'UtfNormalUtil.php'; 37 require_once 'UtfNormal.php'; 38 39 define( 'BENCH_CYCLES', 5 ); 40 41 $testfiles = array( 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' 47 ); 48 $normalizer = new UtfNormal; 49 UtfNormal::loadData(); 50 foreach ( $testfiles as $file => $desc ) { 51 benchmarkTest( $normalizer, $file, $desc ); 52 } 53 54 # ------- 55 56 function benchmarkTest( &$u, $filename, $desc ) { 57 print "Testing $filename ($desc)...\n"; 58 $data = file_get_contents( $filename ); 59 $forms = array( 60 # 'placebo', 61 'cleanUp', 62 'toNFC', 63 # 'toNFKC', 64 # 'toNFD', 'toNFKD', 65 'NFC', 66 # 'NFKC', 67 # 'NFD', 'NFKD', 68 array( 'fastDecompose', 'fastCombiningSort', 'fastCompose' ), 69 # 'quickIsNFC', 'quickIsNFCVerify', 70 ); 71 72 foreach ( $forms as $form ) { 73 if ( is_array( $form ) ) { 74 $str = $data; 75 foreach ( $form as $step ) { 76 $str = benchmarkForm( $u, $str, $step ); 77 } 78 } else { 79 benchmarkForm( $u, $data, $form ); 80 } 81 } 82 } 83 84 function benchmarkForm( &$u, &$data, $form ) { 85 #$start = microtime( true ); 86 for ( $i = 0; $i < BENCH_CYCLES; $i++ ) { 87 $start = microtime( true ); 88 $out = $u->$form( $data, UtfNormal::$utfCanonicalDecomp ); 89 $deltas[] = ( microtime( true ) - $start ); 90 } 91 #$delta = (microtime( true ) - $start) / BENCH_CYCLES; 92 sort( $deltas ); 93 $delta = $deltas[0]; # Take shortest time 94 95 $rate = intval( strlen( $data ) / $delta ); 96 $same = ( 0 == strcmp( $data, $out ) ); 97 98 printf( " %20s %6.1fms %12s bytes/s (%s)\n", 99 $form, 100 $delta * 1000.0, 101 number_format( $rate ), 102 ( $same ? 'no change' : 'changed' ) ); 103 104 return $out; 105 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |