File: CollPerf.pl

package info (click to toggle)
icu 78.2-1
  • links: PTS
  • area: main
  • in suites: experimental
  • size: 123,992 kB
  • sloc: cpp: 527,891; ansic: 112,789; sh: 4,983; makefile: 4,657; perl: 3,199; python: 2,933; xml: 749; sed: 36; lisp: 12
file content (280 lines) | stat: -rwxr-xr-x 8,612 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/perl
#  ********************************************************************
#  * Copyright (C) 2016 and later: Unicode, Inc. and others.
#  * License & terms of use: http://www.unicode.org/copyright.html
#  ********************************************************************
#  * COPYRIGHT:
#  * Copyright (c) 2002-2013, International Business Machines Corporation and
#  * others. All Rights Reserved.
#  ********************************************************************

require "../perldriver/Common.pl";

use lib '../perldriver';

my $p;
if ($OnWindows) {
    $p = "cd ".$ICULatest."/bin && ".$ICUPathLatest . "/collationperf/$WindowsPlatform/Release/collationperf.exe";
}
else {
    $p = "LD_LIBRARY_PATH=".$ICULatest."/source/lib:".$ICULatest."/source/tools/ctestfw ".$ICUPathLatest . "/collationperf/collperf";
}

my @locale = (
    "en_US",
    "da_DK",
    "de_DE",
    "fr_FR",
    "ja_JP",
    "ja_JP",
    "ja_JP",
    "ja_JP",
    "zh_CN",
    "zh_CN",
    "zh_CN",
    "zh_TW",
    "zh_TW",
    "ko_KR",
    "ko_KR",
    "ru_RU",
    "ru_RU",
    "th_TH",
    "th_TH"
);

my $filePath   = $CollationDataPath . "/";
my $filePrefix = "TestNames_";
my @data       = (
    $filePrefix."Latin.txt",
    $filePrefix."Latin.txt",
    $filePrefix."Latin.txt",
    $filePrefix."Latin.txt",
    $filePrefix."Latin.txt",
    $filePrefix."Japanese_h.txt",
    $filePrefix."Japanese_k.txt",
    $filePrefix."Asian.txt",
    $filePrefix."Latin.txt",
    $filePrefix."Chinese.txt",
    $filePrefix."Simplified_Chinese.txt",
    $filePrefix."Latin.txt",
    $filePrefix."Chinese.txt",
    $filePrefix."Latin.txt",
    $filePrefix."Korean.txt",
    $filePrefix."Latin.txt",
    $filePrefix."Russian.txt",
    $filePrefix."Latin.txt",
    $filePrefix."Thai.txt"
);

my @resultPER;
my @resultFIN;

for ( $n = 0 ; $n < @data ; $n++ ) {
    my $resultICU;
    my $resultNIX;
    $resultICU = @locale[$n].",".@data[$n].",";
    $resultNIX = @locale[$n].",".@data[$n].",";
    @resultFIN[$n] = @locale[$n].",".@data[$n].",";

    #quicksort
    my @icu = `$p -locale @locale[$n] -loop 1000 -file $filePath@data[$n] -qsort`;
    my @nix = `$p -locale @locale[$n] -unix -loop 1000 -file $filePath@data[$n] -qsort`;

    my @icua = split( ' = ', $icu[2] );
    my @icub = split( ' ',   $icua[1] );
    my @nixa = split( ' = ', $nix[2] );
    my @nixb = split( ' ',   $nixa[1] );

    $resultICU = $resultICU.$icub[0].",";
    $resultNIX = $resultNIX.$nixb[0].",";

    #keygen time
    @icu = `$p -locale @locale[$n] -loop 1000 -file $filePath@data[$n] -keygen`;
    @nix = `$p -locale @locale[$n] -unix -loop 1000 -file $filePath@data[$n] -keygen`;

    @icua = split( ' = ', $icu[2] );
    @icub = split( ' ',   $icua[1] );
    @nixa = split( ' = ', $nix[2] );
    @nixb = split( ' ',   $nixa[1] );

    $resultICU = $resultICU.$icub[0].",";
    $resultNIX = $resultNIX.$nixb[0].",";

    #keygen len
    @icua = split( ' = ', $icu[3] );
    @nixa = split( ' = ', $nix[3] );

    chomp( @icua[1] );
    chomp( @nixa[1] );

    $resultICU = $resultICU.$icua[1].",";
    $resultNIX = $resultNIX.$nixa[1].",";

    my @resultSplitICU;
    my @resultSplitNIX;

    #percent
    for ( $i = 0 ; $i < 3 ; $i++ ) {
        my $percent = 0;
        @resultSplitICU = split( ',', $resultICU );
        @resultSplitNIX = split( ',', $resultNIX );
        if ( @resultSplitICU[ 2 + $i ] > 0 ) {
            $percent = substr((((
                @resultSplitNIX[ 2 + $i ] - @resultSplitICU[ 2 + $i ]) / @resultSplitICU[ 2 + $i ]) * 100),
                0, 7);
        }
        @resultPER[$n] = @resultPER[$n].$percent."%,";
    }

    #store ICU result
    for ( $j = 0 ; $j < 3 ; $j++ ) {
        @resultFIN[$n] = @resultFIN[$n].@resultSplitICU[ 2 + $j ].",";
    }

    #store Unix result
    for ( $j = 0 ; $j < 3 ; $j++ ) {
        @resultFIN[$n] = @resultFIN[$n].@resultSplitNIX[ 2 + $j ].",";
    }

    #store Percent result
    @resultFIN[$n] = @resultFIN[$n].@resultPER[$n];
}

# Print the results in a HTML page
printOutput();

exit(0);

# This subroutine creates the web page and prints out the results in a table
sub printOutput {
    my $title = "Collation:  ICU " . $ICULatestVersion . " vs GLIBC";
    my $html  = localtime;
    $html =~ s/://g;         # ':' illegal
    $html =~ s/\s*\d+$//;    # delete year
    $html =~ s/^\w+\s*//;    # delete dow
    $html = "CollationPerformance $html.html";
    $html = "../results/" . $html;
    $html =~ s/ /_/g;
    open( HTML, ">$html" ) or die "Can't write to $html: $!";
    print HTML <<EOF;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Collation: ICU4C vs. glibc</title>
<link rel="stylesheet" href="../icu.css" type="text/css" />
</head>
<body>
<!--#include virtual="../ssi/header.html" -->
EOF

    print HTML "<h2>Collation: ICU4C ".$ICULatestVersion." vs. GLIBC</h2>\n";

    print HTML <<EOF;
<p>The performance test takes a locale and creates a RuleBasedCollator with
default options. A large list of names is used as data in each test, where the
names vary according to language. Each Collation operation over the whole list
is repeated 1000 times. The percentage values in the final column are the most
useful. They measure differences, where positive is better for ICU4C, and
negative is better for the compared implementation.</p>
<h3>Key</h3>
<table border="1" cellspacing="0" cellpadding="4">
<tr>
<th align="left">Operation</th>
<th align="left">Units</th>
<th align="left">Description</th>
</tr>
<tr>
<td>strcoll</td>
<td>nanosecs</td>
<td>Timing for string collation, an incremental compare of strings.</td>
</tr>
<tr>
<td>keygen</td>
<td>nanosecs</td>
<td>Timing for generation of sort keys, used to 'precompile' information so
that subsequent operations can use binary comparison.</td>
</tr>
<tr>
<td>keylen</td>
<td>bytes/char</td>
<td>The average length of the generated sort keys, in bytes per character
(Unicode/ISO 10646 code point). Generally this is the important field for sort
key performance, since it directly impacts the time necessary for binary
comparison, and the overhead of memory usage and retrieval time for sort
keys.</td>
</tr>
</table>
EOF
    printData();
    
    print HTML <<EOF;
<h3><i>Notes</i></h3>
<ol>
<li>As with all performance measurements, the results will vary according to
the hardware and compiler. The strcoll operation is particularly sensitive; we
have found that even slight changes in code alignment can produce 10%
differences.</li>
<li>For more information on incremental vs. sort key comparison, the importance
of multi-level sorting, and other features of collation, see <a href=
"http://www.unicode.org/reports/tr10/">Unicode Collation (UCA)</a>.</li>
<li>For general information on ICU collation see <a href=
"/userguide/Collate_Intro.html">User Guide</a>.</li>
<li>For information on APIs, see <a href="/apiref/icu4c/ucol_8h.html">C</a>,
<a href="/apiref/icu4c/classCollator.html">C++</a>, or <a href=
"/apiref/icu4j/com/ibm/icu/text/Collator.html">Java</a>.</li>
</ol>
<!--#include virtual="../ssi/footer.html" -->
</body>
</html>

EOF

    close(HTML) or die "Can't close $html: $!";
}

# This subroutine formats and prints the table.
sub printData() {
    print HTML <<EOF;
<h3>Data</h3>
<table border="1" cellspacing="0" cellpadding="4">
<tr>
<td align="left"><b>Locale</b></td>
<td align="left"><b>Data file</b></td>
<td align="left"><b>strcoll</b> <i>(ICU)</i></td>
<td align="left"><b>keygen</b> <i>(ICU)</i></td>
<td align="left"><b>keylen</b> <i>(ICU)</i></td>
<td align="left"><b>strcoll</b> <i>(GLIBC)</i></td>
<td align="left"><b>keygen</b> <i>(GLIBC)</i></td>
<td align="left"><b>keylen</b> <i>(GLIBC)</i></td>
<td align="left"><b>strcoll</b> <i>(GLIBC-ICU)/ICU)</i></td>
<td align="left"><b>keygen</b> <i>(GLIBC-ICU)/ICU)</i></td>
<td align="left"><b>keylen</b> <i>(GLIBC-ICU)/ICU)</i></td>
</tr>
EOF

    for ( $n = 0 ; $n < @resultFIN ; $n++ ) {
        print HTML "<tr>";
        my @parsed = split( ',', @resultFIN[$n] );
        for ( $i = 0 ; $i < @parsed ; $i++ ) {
            my $value = @parsed[$i];
            print HTML "<td align=\"center\">";

            if ( $value =~ m/^[-]/ ) {
                print HTML "<font color=\"red\">$value</font>";
            }
            else {
                print HTML "$value";
            }

            print HTML "</td>";

        }
        print HTML "</tr>\n";
    }

    print HTML<<EOF;
</table>
EOF
}