Separate out the external links tests
[mediawiki.git] / includes / normal / UtfNormalBench.php
blobc37fb469283bdb3bbe7372e248b45bfbadc670ac
1 <?php
2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # http://www.gnu.org/copyleft/gpl.html
20 /**
22 * @package MediaWiki
25 /** */
26 require_once 'UtfNormalUtil.php';
27 require_once 'UtfNormal.php';
29 define( 'BENCH_CYCLES', 3 );
31 if( php_sapi_name() != 'cli' ) {
32 die( "Run me from the command line please.\n" );
35 $testfiles = array(
36 'testdata/washington.txt' => 'English text',
37 'testdata/berlin.txt' => 'German text',
38 'testdata/tokyo.txt' => 'Japanese text',
39 'testdata/byzantium.txt' => 'Korean text'
41 $normalizer = new UtfNormal;
42 foreach( $testfiles as $file => $desc ) {
43 benchmarkTest( $normalizer, $file, $desc );
46 # -------
48 function benchmarkTest( &$u, $filename, $desc ) {
49 print "Testing $filename ($desc)...\n";
50 $data = file_get_contents( $filename );
51 $forms = array( 'placebo',
52 'cleanUp',
53 'toNFC',
54 # 'toNFKC',
55 # 'toNFD', 'toNFKD',
56 'NFC',
57 # 'NFKC',
58 # 'NFD', 'NFKD',
59 # 'fastDecompose', 'fastCombiningSort', 'fastCompose',
60 'quickIsNFC', 'quickIsNFCVerify',
62 foreach( $forms as $form ) {
63 benchmarkForm( $u, $data, $form );
67 function benchTime(){
68 $st = explode( ' ', microtime() );
69 return (float)$st[0] + (float)$st[1];
72 function benchmarkForm( &$u, &$data, $form ) {
73 global $utfCanonicalDecomp;
74 $start = benchTime();
75 for( $i = 0; $i < BENCH_CYCLES; $i++ ) {
76 $out = $u->$form( $data, $utfCanonicalDecomp );
78 $delta = (benchTime() - $start) / BENCH_CYCLES;
79 $rate = IntVal( strlen( $data ) / $delta );
80 $same = (0 == strcmp( $data, $out ) );
82 printf( " %20s %1.4fs %8d bytes/s (%s)\n", $form, $delta, $rate, ($same ? 'no change' : 'changed' ) );