]> git.saurik.com Git - wxWidgets.git/blame - tests/benchmarks/mbconv.cpp
Minor corrections to wxFlexGridSizer ctor documentation.
[wxWidgets.git] / tests / benchmarks / mbconv.cpp
CommitLineData
3e356d41
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: tests/benchmarks/mbconv.cpp
3// Purpose: MB<->WC conversion benchmarks
4// Author: Vadim Zeitlin
5// Created: 2008-10-17
6// RCS-ID: $Id$
7// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8// Licence: wxWindows license
9/////////////////////////////////////////////////////////////////////////////
10
11#include "wx/strconv.h"
12#include "wx/string.h"
13
14#include "bench.h"
15
16namespace
17{
18
19const 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."
27 ;
28
29// just compute the length of the resulting multibyte string
30bool ComputeMBLength(const wxMBConv& conv)
31{
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();
36}
37
38// perform the conversion
39bool ConvertToMB(const wxMBConv& conv)
40{
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;
44}
45
46} // anonymous namespace
47
48BENCHMARK_FUNC(UTF16InitWX)
49{
50 wxMBConvUTF16 conv;
51 return true;
52}
53
54BENCHMARK_FUNC(UTF16InitSys)
55{
56 wxCSConv conv("UTF-16LE");
57 return conv.IsOk();
58}
59
60BENCHMARK_FUNC(UTF16LenWX)
61{
62 return ComputeMBLength(wxMBConvUTF16());
63}
64
65BENCHMARK_FUNC(UTF16LenSys)
66{
67 return ComputeMBLength(wxCSConv("UTF-16LE"));
68}
69
70BENCHMARK_FUNC(UTF16WX)
71{
72 return ConvertToMB(wxMBConvUTF16());
73}
74
75BENCHMARK_FUNC(UTF16Sys)
76{
77 return ConvertToMB(wxCSConv("UTF-16LE"));
78}
79