xref: /aosp_15_r20/external/icu/icu4j/perf-tests/collationperf.pl (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker#/**
2*0e209d39SAndroid Build Coastguard Worker# * © 2016 and later: Unicode, Inc. and others.
3*0e209d39SAndroid Build Coastguard Worker# * License & terms of use: http://www.unicode.org/copyright.html
4*0e209d39SAndroid Build Coastguard Worker# *******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker# * Copyright (C) 2002-2014, International Business Machines Corporation and    *
6*0e209d39SAndroid Build Coastguard Worker# * others. All Rights Reserved.                                                *
7*0e209d39SAndroid Build Coastguard Worker# *******************************************************************************
8*0e209d39SAndroid Build Coastguard Worker# */
9*0e209d39SAndroid Build Coastguard Worker#
10*0e209d39SAndroid Build Coastguard Worker#  ICU and Windows Collation performance test script
11*0e209d39SAndroid Build Coastguard Worker#      Used in conjunction with the collperf test program.
12*0e209d39SAndroid Build Coastguard Worker#      This script defines the locales and data files to be tested,
13*0e209d39SAndroid Build Coastguard Worker#        runs the collperf program, and formats and prints the results.
14*0e209d39SAndroid Build Coastguard Worker#
15*0e209d39SAndroid Build Coastguard Worker#        7 June 2001   Andy Heninger
16*0e209d39SAndroid Build Coastguard Worker#
17*0e209d39SAndroid Build Coastguard Worker#  ICU4J and Java Collator performance test script
18*0e209d39SAndroid Build Coastguard Worker#  2002-09-25 modified by Richard Liang
19*0e209d39SAndroid Build Coastguard Worker
20*0e209d39SAndroid Build Coastguard Workerprint "To run this performance test\n";
21*0e209d39SAndroid Build Coastguard Workerprint "run perl collationperf.pl\n";
22*0e209d39SAndroid Build Coastguard Workerprint "Running performance tests...\n";
23*0e209d39SAndroid Build Coastguard Worker
24*0e209d39SAndroid Build Coastguard Worker#
25*0e209d39SAndroid Build Coastguard Worker# Map defines the set of data files to run in each locale
26*0e209d39SAndroid Build Coastguard Worker#
27*0e209d39SAndroid Build Coastguard Worker%dataFiles = (
28*0e209d39SAndroid Build Coastguard Worker   "en_US",         "TestNames_Latin.txt",
29*0e209d39SAndroid Build Coastguard Worker   "da_DK",         "TestNames_Latin.txt",
30*0e209d39SAndroid Build Coastguard Worker   "de_DE",         "TestNames_Latin.txt",
31*0e209d39SAndroid Build Coastguard Worker   "de__PHONEBOOK", "TestNames_Latin.txt",
32*0e209d39SAndroid Build Coastguard Worker   "fr_FR",         "TestNames_Latin.txt",
33*0e209d39SAndroid Build Coastguard Worker   "ja_JP",         "TestNames_Latin.txt TestNames_Japanese_h.txt TestNames_Japanese_k.txt TestNames_Asian.txt",
34*0e209d39SAndroid Build Coastguard Worker   "zh_CN",         "TestNames_Latin.txt TestNames_Chinese.txt",
35*0e209d39SAndroid Build Coastguard Worker   "zh_TW",         "TestNames_Latin.txt TestNames_Chinese.txt",
36*0e209d39SAndroid Build Coastguard Worker   "zh__PINYIN",    "TestNames_Latin.txt TestNames_Chinese.txt",
37*0e209d39SAndroid Build Coastguard Worker   "ru_RU", 	    "TestNames_Latin.txt TestNames_Russian.txt",
38*0e209d39SAndroid Build Coastguard Worker   "th",            "TestNames_Latin.txt TestNames_Thai.txt",
39*0e209d39SAndroid Build Coastguard Worker   "ko_KR",         "TestNames_Latin.txt TestNames_Korean.txt",
40*0e209d39SAndroid Build Coastguard Worker   );
41*0e209d39SAndroid Build Coastguard Worker
42*0e209d39SAndroid Build Coastguard Workerif ($^O eq "MSWin32") {
43*0e209d39SAndroid Build Coastguard Worker    $classPath = "out\\lib\\icu4j-perf-tests.jar;..\\icu4j.jar";
44*0e209d39SAndroid Build Coastguard Worker} else {
45*0e209d39SAndroid Build Coastguard Worker    $classPath = "out/lib/icu4j-perf-tests.jar:../icu4j.jar";
46*0e209d39SAndroid Build Coastguard Worker}
47*0e209d39SAndroid Build Coastguard Worker
48*0e209d39SAndroid Build Coastguard Worker#
49*0e209d39SAndroid Build Coastguard Worker#  Outer loop runs through the locales to test
50*0e209d39SAndroid Build Coastguard Worker#     (Edit this list directly to make changes)
51*0e209d39SAndroid Build Coastguard Worker#
52*0e209d39SAndroid Build Coastguard Worker   foreach $locale (
53*0e209d39SAndroid Build Coastguard Worker       "en_US",
54*0e209d39SAndroid Build Coastguard Worker       "da_DK",
55*0e209d39SAndroid Build Coastguard Worker       "de_DE",
56*0e209d39SAndroid Build Coastguard Worker       "de__PHONEBOOK",
57*0e209d39SAndroid Build Coastguard Worker       "fr_FR",
58*0e209d39SAndroid Build Coastguard Worker       "ja_JP",
59*0e209d39SAndroid Build Coastguard Worker       "zh_CN",
60*0e209d39SAndroid Build Coastguard Worker       "zh_TW",
61*0e209d39SAndroid Build Coastguard Worker       "zh__PINYIN",
62*0e209d39SAndroid Build Coastguard Worker       "ko_KR",
63*0e209d39SAndroid Build Coastguard Worker       "ru_RU",
64*0e209d39SAndroid Build Coastguard Worker       "th",
65*0e209d39SAndroid Build Coastguard Worker                   )
66*0e209d39SAndroid Build Coastguard Worker       {
67*0e209d39SAndroid Build Coastguard Worker       #
68*0e209d39SAndroid Build Coastguard Worker       # Inner loop runs over the set of data files specified for each locale.
69*0e209d39SAndroid Build Coastguard Worker       #    (Edit the %datafiles initialization, above, to make changes.
70*0e209d39SAndroid Build Coastguard Worker       #
71*0e209d39SAndroid Build Coastguard Worker       $ff = $dataFiles{$locale};
72*0e209d39SAndroid Build Coastguard Worker       @ff = split(/[\s]+/, $ff);
73*0e209d39SAndroid Build Coastguard Worker       foreach $data (@ff) {
74*0e209d39SAndroid Build Coastguard Worker
75*0e209d39SAndroid Build Coastguard Worker          #
76*0e209d39SAndroid Build Coastguard Worker          # Run ICU Test for this (locale, data file) pair.
77*0e209d39SAndroid Build Coastguard Worker          #
78*0e209d39SAndroid Build Coastguard Worker          $iStrCol = `java -classpath $classPath com.ibm.icu.dev.test.perf.CollationPerformanceTest -terse -file data/collation/$data -locale $locale -loop 1000 -binsearch`;
79*0e209d39SAndroid Build Coastguard Worker          $iStrCol =~s/[,\s]*//g;  # whack off the leading "  ," in the returned result.
80*0e209d39SAndroid Build Coastguard Worker          doKeyTimes("java -classpath $classPath com.ibm.icu.dev.test.perf.CollationPerformanceTest -terse -file data/collation/$data -locale $locale -loop 1000 -keygen",
81*0e209d39SAndroid Build Coastguard Worker                     $iKeyGen, $iKeyLen);
82*0e209d39SAndroid Build Coastguard Worker
83*0e209d39SAndroid Build Coastguard Worker
84*0e209d39SAndroid Build Coastguard Worker          #
85*0e209d39SAndroid Build Coastguard Worker          # Run Windows test for this (locale, data file) pair.  Only do if
86*0e209d39SAndroid Build Coastguard Worker          #    we are not on Windows 98/ME and we hava a windows langID
87*0e209d39SAndroid Build Coastguard Worker          #    for the locale.
88*0e209d39SAndroid Build Coastguard Worker          #
89*0e209d39SAndroid Build Coastguard Worker          $wStrCol = $wKeyGen = $wKeyLen = 0;
90*0e209d39SAndroid Build Coastguard Worker          $wStrCol = `java -classpath $classPath com.ibm.icu.dev.test.perf.CollationPerformanceTest -terse -file data/collation/$data -locale $locale -loop 1000 -binsearch -java`;
91*0e209d39SAndroid Build Coastguard Worker          $wStrCol =~s/[,\s]*//g;  # whack off the leading "  ," in the returned result.
92*0e209d39SAndroid Build Coastguard Worker          doKeyTimes("java -classpath $classPath com.ibm.icu.dev.test.perf.CollationPerformanceTest -terse -file data/collation/$data -locale $locale -loop 1000 -keygen -java",
93*0e209d39SAndroid Build Coastguard Worker                     $wKeyGen, $wKeyLen);
94*0e209d39SAndroid Build Coastguard Worker
95*0e209d39SAndroid Build Coastguard Worker          $collDiff = $keyGenDiff = $keyLenDiff = 0;
96*0e209d39SAndroid Build Coastguard Worker          if ($wKeyLen > 0) {
97*0e209d39SAndroid Build Coastguard Worker              $collDiff   = (($wStrCol - $iStrCol) / $iStrCol) * 100;
98*0e209d39SAndroid Build Coastguard Worker              $keyGenDiff = (($wKeyGen - $iKeyGen) / $iKeyGen) * 100;
99*0e209d39SAndroid Build Coastguard Worker              $keyLenDiff = (($wKeyLen - $iKeyLen) / $iKeyLen) * 100;
100*0e209d39SAndroid Build Coastguard Worker          }
101*0e209d39SAndroid Build Coastguard Worker
102*0e209d39SAndroid Build Coastguard Worker         #
103*0e209d39SAndroid Build Coastguard Worker         #  Write the line of results for this (locale, data file).
104*0e209d39SAndroid Build Coastguard Worker         #
105*0e209d39SAndroid Build Coastguard Worker         write;
106*0e209d39SAndroid Build Coastguard Worker    }
107*0e209d39SAndroid Build Coastguard Worker }
108*0e209d39SAndroid Build Coastguard Worker
109*0e209d39SAndroid Build Coastguard Worker#
110*0e209d39SAndroid Build Coastguard Worker#  doKeyGenTimes($Command_to_run, $time, $key_length)
111*0e209d39SAndroid Build Coastguard Worker#       Do a key-generation test and return the time and key length/char values.
112*0e209d39SAndroid Build Coastguard Worker#
113*0e209d39SAndroid Build Coastguard Workersub doKeyTimes($$$) {
114*0e209d39SAndroid Build Coastguard Worker   # print "$_[0]\n";
115*0e209d39SAndroid Build Coastguard Worker   local($x) = `$_[0]`;                  # execute the collperf command.
116*0e209d39SAndroid Build Coastguard Worker   ($_[1], $_[2]) = split(/\,/, $x);     # collperf returns "time, keylength" string.
117*0e209d39SAndroid Build Coastguard Worker}
118*0e209d39SAndroid Build Coastguard Worker
119*0e209d39SAndroid Build Coastguard Worker
120*0e209d39SAndroid Build Coastguard Worker#
121*0e209d39SAndroid Build Coastguard Worker#  Output Formats ...
122*0e209d39SAndroid Build Coastguard Worker#
123*0e209d39SAndroid Build Coastguard Worker#
124*0e209d39SAndroid Build Coastguard Workerformat STDOUT_TOP =
125*0e209d39SAndroid Build Coastguard Worker                                      -------- ICU --------   ------ JAVA -------      (JAVA - ICU)/ICU
126*0e209d39SAndroid Build Coastguard WorkerLocale     Data file                  strcoll keygen  keylen  strcoll keygen  keylen    coll  keygen  keylen
127*0e209d39SAndroid Build Coastguard Worker------------------------------------------------------------------------------------------------------------
128*0e209d39SAndroid Build Coastguard Worker.
129*0e209d39SAndroid Build Coastguard Worker
130*0e209d39SAndroid Build Coastguard Workerformat STDOUT =
131*0e209d39SAndroid Build Coastguard Worker@<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<| @######  @####   @#.##  |@##### @#####   @#.## | @###%  @###%   @###%
132*0e209d39SAndroid Build Coastguard Worker$locale, $data, $iStrCol, $iKeyGen, $iKeyLen, $wStrCol, $wKeyGen, $wKeyLen, $collDiff, $keyGenDiff, $keyLenDiff
133*0e209d39SAndroid Build Coastguard Worker.
134