ILIAS
Release_4_0_x_branch Revision 61816
◀ ilDoc Overview
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
Examples
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Groups
Pages
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
28
if
( isset( $_SERVER[
'argv'
] ) && in_array(
'--icu'
, $_SERVER[
'argv'
] ) ) {
29
dl(
'php_utfnormal.so'
);
30
}
31
32
require_once
'UtfNormalUtil.php'
;
33
require_once
'UtfNormal.php'
;
34
35
define(
'BENCH_CYCLES'
, 5 );
36
37
if
( php_sapi_name() !=
'cli'
) {
38
die(
"Run me from the command line please.\n"
);
39
}
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
foreach
( $forms as $form ) {
72
if
( is_array( $form ) ) {
73
$str =
$data
;
74
foreach
( $form as $step ) {
75
$str =
benchmarkForm
( $u, $str, $step );
76
}
77
}
else
{
78
benchmarkForm
( $u,
$data
, $form );
79
}
80
}
81
}
82
83
function
benchTime
(){
84
$st = explode(
' '
, microtime() );
85
return
(
float
)$st[0] + (float)$st[1];
86
}
87
88
function
benchmarkForm
( &$u, &
$data
, $form ) {
89
global
$utfCanonicalDecomp
;
90
#$start = benchTime();
91
for
( $i = 0; $i <
BENCH_CYCLES
; $i++ ) {
92
$start
=
benchTime
();
93
$out
= $u->$form(
$data
, $utfCanonicalDecomp );
94
$deltas[] = (
benchTime
() -
$start
);
95
}
96
#$delta = (benchTime() - $start) / BENCH_CYCLES;
97
sort( $deltas );
98
$delta = $deltas[0]; # Take shortest time
99
100
$rate = intval( strlen(
$data
) / $delta );
101
$same = (0 == strcmp(
$data
,
$out
) );
102
103
printf(
" %20s %6.1fms %12s bytes/s (%s)\n"
,
104
$form,
105
$delta*1000.0,
106
number_format( $rate ),
107
($same ?
'no change'
:
'changed'
) );
108
return
$out
;
109
}
110
111
?>
Modules
Wiki
mediawiki
normal
UtfNormalBench.php
Generated on Wed Apr 27 2016 19:01:28 for ILIAS by
1.8.1.2 (using
Doxyfile
)