ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
UtfNormalBench.php
Go to the documentation of this file.
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.
14#
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# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18# http://www.gnu.org/copyleft/gpl.html
19
28if( isset( $_SERVER['argv'] ) && in_array( '--icu', $_SERVER['argv'] ) ) {
29 dl( 'php_utfnormal.so' );
30}
31
32require_once 'include/Unicode/UtfNormal.php';
33
34define( 'BENCH_CYCLES', 5 );
35
36if( php_sapi_name() != 'cli' ) {
37 die( "Run me from the command line please.\n" );
38}
39
40$testfiles = array(
41 'testdata/washington.txt' => 'English text',
42 'testdata/berlin.txt' => 'German text',
43 'testdata/bulgakov.txt' => 'Russian text',
44 'testdata/tokyo.txt' => 'Japanese text',
45 'testdata/young.txt' => 'Korean text'
46);
49foreach( $testfiles as $file => $desc ) {
51}
52
53# -------
54
55function benchmarkTest( &$u, $filename, $desc ) {
56 print "Testing $filename ($desc)...\n";
57 $data = file_get_contents( $filename );
58 $forms = array(
59# 'placebo',
60 'cleanUp',
61 'toNFC',
62# 'toNFKC',
63# 'toNFD', 'toNFKD',
64 'NFC',
65# 'NFKC',
66# 'NFD', 'NFKD',
67 array( 'fastDecompose', 'fastCombiningSort', 'fastCompose' ),
68# 'quickIsNFC', 'quickIsNFCVerify',
69 );
70 foreach( $forms as $form ) {
71 if( is_array( $form ) ) {
72 $str = $data;
73 foreach( $form as $step ) {
74 $str = benchmarkForm( $u, $str, $step );
75 }
76 } else {
77 benchmarkForm( $u, $data, $form );
78 }
79 }
80}
81
82function benchTime(){
83 $st = explode( ' ', microtime() );
84 return (float)$st[0] + (float)$st[1];
85}
86
87function benchmarkForm( &$u, &$data, $form ) {
89 #$start = benchTime();
90 for( $i = 0; $i < BENCH_CYCLES; $i++ ) {
91 $start = benchTime();
92 $out = $u->$form( $data, $utfCanonicalDecomp );
93 $deltas[] = (benchTime() - $start);
94 }
95 #$delta = (benchTime() - $start) / BENCH_CYCLES;
96 sort( $deltas );
97 $delta = $deltas[0]; # Take shortest time
98
99 $rate = intval( strlen( $data ) / $delta );
100 $same = (0 == strcmp( $data, $out ) );
101
102 printf( " %20s %6.1fms %12s bytes/s (%s)\n",
103 $form,
104 $delta*1000.0,
105 number_format( $rate ),
106 ($same ? 'no change' : 'changed' ) );
107 return $out;
108}
109
110?>
benchTime()
foreach($testfiles as $file=> $desc) benchmarkTest(&$u, $filename, $desc)
const BENCH_CYCLES
benchmarkForm(&$u, &$data, $form)
$normalizer
if(php_sapi_name() !='cli') $testfiles
if(! $in) print
global $utfCanonicalDecomp
Definition: UtfNormal.php:23
An exception for terminatinating execution or to throw for unit testing.
static loadData()
Load the basic composition data if necessary.
Definition: UtfNormal.php:221
foreach($_REQUEST as $var) foreach(array('_POST'=> 'HTTP_POST_VARS', '_GET'=> 'HTTP_GET_VARS', '_COOKIE'=> 'HTTP_COOKIE_VARS', '_SERVER'=> 'HTTP_SERVER_VARS', '_ENV'=> 'HTTP_ENV_VARS', '_FILES'=> 'HTTP_POST_FILES') as $array=> $other) $step
Definition: cssgen.php:155
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']