]>
git.saurik.com Git - wxWidgets.git/blob - tests/benchmarks/mbconv.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tests/benchmarks/mbconv.cpp
3 // Purpose: MB<->WC conversion benchmarks
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/strconv.h"
11 #include "wx/string.h"
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."
28 // just compute the length of the resulting multibyte string
29 bool ComputeMBLength(const wxMBConv
& conv
)
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();
37 // perform the conversion
38 bool ConvertToMB(const wxMBConv
& conv
)
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
;
45 } // anonymous namespace
47 BENCHMARK_FUNC(UTF16InitWX
)
53 BENCHMARK_FUNC(UTF16InitSys
)
55 wxCSConv
conv("UTF-16LE");
59 BENCHMARK_FUNC(UTF16LenWX
)
61 return ComputeMBLength(wxMBConvUTF16());
64 BENCHMARK_FUNC(UTF16LenSys
)
66 return ComputeMBLength(wxCSConv("UTF-16LE"));
69 BENCHMARK_FUNC(UTF16WX
)
71 return ConvertToMB(wxMBConvUTF16());
74 BENCHMARK_FUNC(UTF16Sys
)
76 return ConvertToMB(wxCSConv("UTF-16LE"));