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