]> git.saurik.com Git - wxWidgets.git/blame - tests/benchmarks/printfbench.cpp
Add a unit test for wxImage::Scale() method.
[wxWidgets.git] / tests / benchmarks / printfbench.cpp
CommitLineData
412a5c57
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: printfbench.cpp
7b4138e2 3// Purpose: benchmarks for wx*Printf*() functions
412a5c57
VZ
4// Author: Francesco Montorsi
5// Modified by:
6// Created: 27/3/2006
7// RCS-ID: $Id$
7b4138e2 8// Copyright: (c) 2006-2009 Francesco Montorsi
526954c5 9// Licence: wxWindows licence
412a5c57
VZ
10/////////////////////////////////////////////////////////////////////////////
11
7b4138e2
FM
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
a15302de
FM
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
7b4138e2
FM
44#include "wx/string.h"
45#include "bench.h"
412a5c57
VZ
46
47// ----------------------------------------------------------------------------
48// constants
49// ----------------------------------------------------------------------------
50
412a5c57
VZ
51#define BUFSIZE 10000
52
412a5c57 53const wxString g_verylongString =
7b4138e2
FM
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";
412a5c57
VZ
56
57
58// ----------------------------------------------------------------------------
59// benchmarking helpers
60// ----------------------------------------------------------------------------
61
7b4138e2
FM
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, " \
53c2cdb0
FM
65 prefix##"and is used as benchmark for %s - %% %.2f %d %s", \
66 prefix##"(many!!)", 6, "this program", 23.342f, 999, \
7b4138e2 67 (const char*)g_verylongString.c_str());
412a5c57 68
7b4138e2
FM
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 " \
53c2cdb0
FM
72 prefix##"for our benchmarking aims - %% %3$f %5$d %4$s", \
73 prefix##"test it", "string with positional arguments", 23.342f, \
7b4138e2 74 (const char*)g_verylongString.c_str(), 999);
412a5c57 75
7b4138e2
FM
76#define DO_BENCHMARK(fnc, prefix) \
77 fnc(buffer, BUFSIZE, prefix##"This is a short %s string with very few words", "test");
412a5c57 78
7b4138e2
FM
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");
412a5c57
VZ
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
412a5c57
VZ
102
103// ----------------------------------------------------------------------------
104// main
105// ----------------------------------------------------------------------------
106
7b4138e2 107BENCHMARK_FUNC(SnprintfWithPositionals)
412a5c57 108{
412a5c57 109 wxChar buffer[BUFSIZE];
412a5c57 110#if wxUSE_PRINTF_POS_PARAMS
7b4138e2
FM
111 DO_LONG_POSITIONAL_BENCHMARK(wxSnprintf, )
112 DO_POSITIONAL_BENCHMARK(wxSnprintf, )
412a5c57 113#endif
7b4138e2
FM
114 return true;
115}
412a5c57 116
7b4138e2
FM
117BENCHMARK_FUNC(Snprintf)
118{
119 wxChar buffer[BUFSIZE];
120 DO_LONG_BENCHMARK(wxSnprintf, )
121 DO_BENCHMARK(wxSnprintf, )
122 return true;
123}
412a5c57 124
7b4138e2
FM
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}
412a5c57 132
7b4138e2
FM
133BENCHMARK_FUNC(SystemSnprintf)
134{
135 wxChar buffer[BUFSIZE];
136 DO_LONG_BENCHMARK(sys_printf, L)
137 DO_BENCHMARK(sys_printf, L)
138 return true;
412a5c57
VZ
139}
140