]> git.saurik.com Git - wxWidgets.git/blame_incremental - tests/benchmarks/printfbench.cpp
Implement wxGetHostName() for Windows CE.
[wxWidgets.git] / tests / benchmarks / printfbench.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: printfbench.cpp
3// Purpose: benchmarks for wx*Printf*() functions
4// Author: Francesco Montorsi
5// Modified by:
6// Created: 27/3/2006
7// RCS-ID: $Id$
8// Copyright: (c) 2006-2009 Francesco Montorsi
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12/*
13 TODO: revise the benchmarking functions below to allow valid comparisons
14 between the wx implementation and the system's implementation of
15 the tested functions (e.g. adding tests which use the wxS macro to
16 avoid runtime encoding conversions, etc etc).
17*/
18
19//
20// Profiling under Linux:
21// =====================
22//
23// 1) configure wxWidgets in release mode
24// 2) make sure that HAVE_UNIX98_PRINTF is undefined (just #defining it to zero
25// does not work; you must comment out the entire #define) in your setup.h;
26// and also that wxUSE_PRINTF_POS_PARAMS is set to 1; this will force the
27// use of wx's own implementation of wxVsnprintf()
28// 3) compile wx
29// 4) set wxTEST_WX_ONLY to 1 and compile tests as well
30//
31// Now you have two main choices:
32//
33// - using gprof:
34// 5) add to the Makefile of this test program the -pg option both to
35// CXXFLAGS and to LDFLAGS
36// 6) run the test
37// 7) look at the gmon.out file with gprof utility
38//
39// - using valgrind:
40// 4) run "valgrind --tool=callgrind ./printfbench"
41// 5) run "kcachegrind dump_file_generated_by_callgrind"
42//
43
44#include "wx/string.h"
45#include "bench.h"
46
47// ----------------------------------------------------------------------------
48// constants
49// ----------------------------------------------------------------------------
50
51#define BUFSIZE 10000
52
53const wxString g_verylongString =
54 "very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very "
55 "very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long string!\n\n\n";
56
57
58// ----------------------------------------------------------------------------
59// benchmarking helpers
60// ----------------------------------------------------------------------------
61
62#define DO_LONG_BENCHMARK(fnc, prefix) \
63 fnc(buffer, BUFSIZE, \
64 prefix##"This is a reasonably long string with various %s arguments, exactly %d, " \
65 prefix##"and is used as benchmark for %s - %% %.2f %d %s", \
66 prefix##"(many!!)", 6, "this program", 23.342f, 999, \
67 (const char*)g_verylongString.c_str());
68
69#define DO_LONG_POSITIONAL_BENCHMARK(fnc, prefix) \
70 fnc(buffer, BUFSIZE, \
71 prefix##"This is a %2$s and thus is harder to parse... let's %1$s " \
72 prefix##"for our benchmarking aims - %% %3$f %5$d %4$s", \
73 prefix##"test it", "string with positional arguments", 23.342f, \
74 (const char*)g_verylongString.c_str(), 999);
75
76#define DO_BENCHMARK(fnc, prefix) \
77 fnc(buffer, BUFSIZE, prefix##"This is a short %s string with very few words", "test");
78
79#define DO_POSITIONAL_BENCHMARK(fnc, prefix) \
80 fnc(buffer, BUFSIZE, \
81 prefix##"This is a %2$s and thus is harder to parse... nonetheless, %1$s !", \
82 "test it", "string with positional arguments");
83
84// the configure script of wxWidgets will define HAVE_UNIX98_PRINTF on those
85// system with a *printf() family of functions conformant to Unix 98 standard;
86// systems without the configure script as build system (e.g. Windows) do not
87// have positional support anyway
88#ifdef HAVE_UNIX98_PRINTF
89 #define wxSYSTEM_HAS_POSPARAM_SUPPORT 1
90#else
91 #define wxSYSTEM_HAS_POSPARAM_SUPPORT 1
92#endif
93
94// we need to avoid the use of wxPrintf() here since it could have been mapped
95// to wxWidgets' implementation of wxVsnPrintf() !
96#if wxUSE_UNICODE
97 #define sys_printf swprintf
98#else
99 #define sys_printf snprintf
100#endif
101
102
103// ----------------------------------------------------------------------------
104// main
105// ----------------------------------------------------------------------------
106
107BENCHMARK_FUNC(SnprintfWithPositionals)
108{
109 wxChar buffer[BUFSIZE];
110#if wxUSE_PRINTF_POS_PARAMS
111 DO_LONG_POSITIONAL_BENCHMARK(wxSnprintf, )
112 DO_POSITIONAL_BENCHMARK(wxSnprintf, )
113#endif
114 return true;
115}
116
117BENCHMARK_FUNC(Snprintf)
118{
119 wxChar buffer[BUFSIZE];
120 DO_LONG_BENCHMARK(wxSnprintf, )
121 DO_BENCHMARK(wxSnprintf, )
122 return true;
123}
124
125BENCHMARK_FUNC(SystemSnprintfWithPositionals)
126{
127 wxChar buffer[BUFSIZE];
128 DO_LONG_POSITIONAL_BENCHMARK(sys_printf, L)
129 DO_POSITIONAL_BENCHMARK(sys_printf, L)
130 return true;
131}
132
133BENCHMARK_FUNC(SystemSnprintf)
134{
135 wxChar buffer[BUFSIZE];
136 DO_LONG_BENCHMARK(sys_printf, L)
137 DO_BENCHMARK(sys_printf, L)
138 return true;
139}
140