#!/usr/bin/perl
# ********************************************************************
# * Copyright (C) 2016 and later: Unicode, Inc. and others.
# * License & terms of use: http://www.unicode.org/copyright.html#License
# ********************************************************************
# * 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 <Collation: ICU4C vs. glibc
EOF
print HTML "
Collation: ICU4C ".$ICULatestVersion." vs. GLIBC
\n";
print HTML <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.
Key
Operation
Units
Description
strcoll
nanosecs
Timing for string collation, an incremental compare of strings.
keygen
nanosecs
Timing for generation of sort keys, used to 'precompile' information so
that subsequent operations can use binary comparison.
keylen
bytes/char
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.
EOF
printData();
print HTML <Notes
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.
For more information on incremental vs. sort key comparison, the importance
of multi-level sorting, and other features of collation, see Unicode Collation (UCA).
For general information on ICU collation see User Guide.