]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: tests/benchmarks/mbconv.cpp | |
3 | // Purpose: MB<->WC conversion benchmarks | |
4 | // Author: Vadim Zeitlin | |
5 | // Created: 2008-10-17 | |
6 | // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org> | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #include "wx/strconv.h" | |
11 | #include "wx/string.h" | |
12 | ||
13 | #include "bench.h" | |
14 | ||
15 | namespace | |
16 | { | |
17 | ||
18 | const wchar_t *TEST_STRING = | |
19 | L"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod" | |
20 | L"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim" | |
21 | L"veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea" | |
22 | L"commodo consequat. Duis aute irure dolor in reprehenderit in voluptate" | |
23 | L"velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint" | |
24 | L"occaecat cupidatat non proident, sunt in culpa qui officia deserunt" | |
25 | L"mollit anim id est laborum." | |
26 | ; | |
27 | ||
28 | // just compute the length of the resulting multibyte string | |
29 | bool ComputeMBLength(const wxMBConv& conv) | |
30 | { | |
31 | // we suppose a fixed length encoding here (which happens to cover UTF-8 | |
32 | // too as long as the test string is ASCII) | |
33 | return conv.FromWChar(NULL, 0, TEST_STRING) | |
34 | == (wcslen(TEST_STRING) + 1)*conv.GetMBNulLen(); | |
35 | } | |
36 | ||
37 | // perform the conversion | |
38 | bool ConvertToMB(const wxMBConv& conv) | |
39 | { | |
40 | const size_t outlen = (wcslen(TEST_STRING) + 1)*conv.GetMBNulLen(); | |
41 | wxCharBuffer buf(outlen - 1); // it adds 1 internally | |
42 | return conv.FromWChar(buf.data(), outlen, TEST_STRING) == outlen; | |
43 | } | |
44 | ||
45 | } // anonymous namespace | |
46 | ||
47 | BENCHMARK_FUNC(UTF16InitWX) | |
48 | { | |
49 | wxMBConvUTF16 conv; | |
50 | return true; | |
51 | } | |
52 | ||
53 | BENCHMARK_FUNC(UTF16InitSys) | |
54 | { | |
55 | wxCSConv conv("UTF-16LE"); | |
56 | return conv.IsOk(); | |
57 | } | |
58 | ||
59 | BENCHMARK_FUNC(UTF16LenWX) | |
60 | { | |
61 | return ComputeMBLength(wxMBConvUTF16()); | |
62 | } | |
63 | ||
64 | BENCHMARK_FUNC(UTF16LenSys) | |
65 | { | |
66 | return ComputeMBLength(wxCSConv("UTF-16LE")); | |
67 | } | |
68 | ||
69 | BENCHMARK_FUNC(UTF16WX) | |
70 | { | |
71 | return ConvertToMB(wxMBConvUTF16()); | |
72 | } | |
73 | ||
74 | BENCHMARK_FUNC(UTF16Sys) | |
75 | { | |
76 | return ConvertToMB(wxCSConv("UTF-16LE")); | |
77 | } | |
78 |