summaryrefslogtreecommitdiff
path: root/icu4c/source/test/perf/localecanperf/localecanperf.cpp
blob: 19fc99d5e2526e57916cec948f52372e44a3c310 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
***********************************************************************
* © 2020 and later: Unicode, Inc. and others.
* License & terms of use: http://www.unicode.org/copyright.html
***********************************************************************
*/

#include <algorithm>
#include <vector>
#include <string>

#include "unicode/locid.h"
#include "unicode/uperf.h"

//
// Test case ...
//
class LocaleCreateCanonical : public UPerfFunction {
public:
    LocaleCreateCanonical() {
        testCases.emplace_back("en");
        testCases.emplace_back("en-US");
        testCases.emplace_back("ja-JP");
        testCases.emplace_back("zh-Hant-CN");
        testCases.emplace_back("hy-SU");
    }
    ~LocaleCreateCanonical() {  }
    virtual void call(UErrorCode* /* status */)
    {
        std::for_each(testCases.begin(), testCases.end(),
                      [](const std::string& s)
                      {
                          Locale l = Locale::createCanonical(s.c_str());
                      });
    }
    virtual long getOperationsPerIteration() { return testCases.size(); }
    virtual long getEventsPerIteration() { return testCases.size(); }
private:
    std::vector<std::string> testCases;
};

class LocaleCanonicalizationPerfTest : public UPerfTest
{
public:
    LocaleCanonicalizationPerfTest(
        int32_t argc, const char *argv[], UErrorCode &status)
            : UPerfTest(argc, argv, nullptr, 0, "localecanperf", status)
    {
    }

    ~LocaleCanonicalizationPerfTest()
    {
    }
    virtual UPerfFunction* runIndexedTest(
        int32_t index, UBool exec, const char *&name, char *par = nullptr);

private:
    UPerfFunction* TestLocaleCreateCanonical()
    {
        return new LocaleCreateCanonical();
    }
};

UPerfFunction*
LocaleCanonicalizationPerfTest::runIndexedTest(
    int32_t index, UBool exec, const char *&name, char *par /*= nullptr*/)
{
    (void)par;
    TESTCASE_AUTO_BEGIN;

    TESTCASE_AUTO(TestLocaleCreateCanonical);

    TESTCASE_AUTO_END;
    return nullptr;
}

int main(int argc, const char *argv[])
{
    UErrorCode status = U_ZERO_ERROR;
    LocaleCanonicalizationPerfTest test(argc, argv, status);

    if (U_FAILURE(status)){
        fprintf(stderr, "The error is %s\n", u_errorName(status));
        test.usage();
        return status;
    }

    if (test.run() == false){
        test.usage();
        fprintf(stderr, "FAILED: Tests could not be run please check the arguments.\n");
        return -1;
    }
    return 0;
}