]>
git.saurik.com Git - wxWidgets.git/blob - tests/benchmarks/mbconv.cpp
a3e51305d6e1ed35f21903691b51d9b066004b3b
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tests/benchmarks/mbconv.cpp
3 // Purpose: MB<->WC conversion benchmarks
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/strconv.h"
12 #include "wx/string.h"
19 const wchar_t *TEST_STRING
=
20 L
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod"
21 L
"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim"
22 L
"veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea"
23 L
"commodo consequat. Duis aute irure dolor in reprehenderit in voluptate"
24 L
"velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint"
25 L
"occaecat cupidatat non proident, sunt in culpa qui officia deserunt"
26 L
"mollit anim id est laborum."
29 // just compute the length of the resulting multibyte string
30 bool ComputeMBLength(const wxMBConv
& conv
)
32 // we suppose a fixed length encoding here (which happens to cover UTF-8
33 // too as long as the test string is ASCII)
34 return conv
.FromWChar(NULL
, 0, TEST_STRING
)
35 == (wcslen(TEST_STRING
) + 1)*conv
.GetMBNulLen();
38 // perform the conversion
39 bool ConvertToMB(const wxMBConv
& conv
)
41 const size_t outlen
= (wcslen(TEST_STRING
) + 1)*conv
.GetMBNulLen();
42 wxCharBuffer
buf(outlen
- 1); // it adds 1 internally
43 return conv
.FromWChar(buf
.data(), outlen
, TEST_STRING
) == outlen
;
46 } // anonymous namespace
48 BENCHMARK_FUNC(UTF16InitWX
)
54 BENCHMARK_FUNC(UTF16InitSys
)
56 wxCSConv
conv("UTF-16LE");
60 BENCHMARK_FUNC(UTF16LenWX
)
62 return ComputeMBLength(wxMBConvUTF16());
65 BENCHMARK_FUNC(UTF16LenSys
)
67 return ComputeMBLength(wxCSConv("UTF-16LE"));
70 BENCHMARK_FUNC(UTF16WX
)
72 return ConvertToMB(wxMBConvUTF16());
75 BENCHMARK_FUNC(UTF16Sys
)
77 return ConvertToMB(wxCSConv("UTF-16LE"));