Frank Tang | 3e05d9d | 2021-11-08 14:04:04 -0800 | [diff] [blame] | 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: |
| 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 | } |
| 27 | ~LocaleCreateCanonical() { } |
| 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 | } |
| 36 | virtual long getOperationsPerIteration() { return testCases.size(); } |
| 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: |
| 45 | LocaleCanonicalizationPerfTest( |
| 46 | int32_t argc, const char *argv[], UErrorCode &status) |
| 47 | : UPerfTest(argc, argv, nullptr, 0, "localecanperf", status) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | ~LocaleCanonicalizationPerfTest() |
| 52 | { |
| 53 | } |
| 54 | virtual UPerfFunction* runIndexedTest( |
| 55 | int32_t index, UBool exec, const char *&name, char *par = nullptr); |
| 56 | |
| 57 | private: |
| 58 | UPerfFunction* TestLocaleCreateCanonical() |
| 59 | { |
| 60 | return new LocaleCreateCanonical(); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | UPerfFunction* |
| 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 | |
| 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 | |
Frank Tang | 1f164ee | 2022-11-08 12:31:27 -0800 | [diff] [blame^] | 88 | if (test.run() == false){ |
Frank Tang | 3e05d9d | 2021-11-08 14:04:04 -0800 | [diff] [blame] | 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 | } |