1 /*
2 ***********************************************************************
3 * © 2020 and later: Unicode, Inc. and others.
4 * License & terms of use: http://www.unicode.org/copyright.html
5 ***********************************************************************
6 */
7 
8 #include <algorithm>
9 #include <vector>
10 #include <string>
11 
12 #include "unicode/locid.h"
13 #include "unicode/uperf.h"
14 
15 //
16 // Test case ...
17 //
18 class LocaleCreateCanonical : public UPerfFunction {
19 public:
LocaleCreateCanonical()20     LocaleCreateCanonical() {
21         testCases.push_back("en");
22         testCases.push_back("en-US");
23         testCases.push_back("ja-JP");
24         testCases.push_back("zh-Hant-CN");
25         testCases.push_back("hy-SU");
26     }
~LocaleCreateCanonical()27     ~LocaleCreateCanonical() {  }
call(UErrorCode *)28     virtual void call(UErrorCode* /* status */)
29     {
30         std::for_each(testCases.begin(), testCases.end(),
31                       [](const std::string& s)
32                       {
33                           Locale l = Locale::createCanonical(s.c_str());
34                       });
35     }
getOperationsPerIteration()36     virtual long getOperationsPerIteration() { return testCases.size(); }
getEventsPerIteration()37     virtual long getEventsPerIteration() { return testCases.size(); }
38 private:
39     std::vector<std::string> testCases;
40 };
41 
42 class LocaleCanonicalizationPerfTest : public UPerfTest
43 {
44 public:
LocaleCanonicalizationPerfTest(int32_t argc,const char * argv[],UErrorCode & status)45     LocaleCanonicalizationPerfTest(
46         int32_t argc, const char *argv[], UErrorCode &status)
47             : UPerfTest(argc, argv, nullptr, 0, "localecanperf", status)
48     {
49     }
50 
~LocaleCanonicalizationPerfTest()51     ~LocaleCanonicalizationPerfTest()
52     {
53     }
54     virtual UPerfFunction* runIndexedTest(
55         int32_t index, UBool exec, const char *&name, char *par = nullptr);
56 
57 private:
TestLocaleCreateCanonical()58     UPerfFunction* TestLocaleCreateCanonical()
59     {
60         return new LocaleCreateCanonical();
61     }
62 };
63 
64 UPerfFunction*
runIndexedTest(int32_t index,UBool exec,const char * & name,char * par)65 LocaleCanonicalizationPerfTest::runIndexedTest(
66     int32_t index, UBool exec, const char *&name, char *par /*= nullptr*/)
67 {
68     (void)par;
69     TESTCASE_AUTO_BEGIN;
70 
71     TESTCASE_AUTO(TestLocaleCreateCanonical);
72 
73     TESTCASE_AUTO_END;
74     return nullptr;
75 }
76 
main(int argc,const char * argv[])77 int main(int argc, const char *argv[])
78 {
79     UErrorCode status = U_ZERO_ERROR;
80     LocaleCanonicalizationPerfTest test(argc, argv, status);
81 
82     if (U_FAILURE(status)){
83         fprintf(stderr, "The error is %s\n", u_errorName(status));
84         test.usage();
85         return status;
86     }
87 
88     if (test.run() == FALSE){
89         test.usage();
90         fprintf(stderr, "FAILED: Tests could not be run please check the arguments.\n");
91         return -1;
92     }
93     return 0;
94 }
95