1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tests/benchmarks/bench.h
3 // Purpose: Main header of the benchmarking suite
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_TESTS_BENCHMARKS_BENCH_H_
12 #define _WX_TESTS_BENCHMARKS_BENCH_H_
21 Utility object used to register the benchmark functions.
28 typedef bool (*InitType
)();
29 typedef bool (*FuncType
)();
30 typedef void (*DoneType
)();
32 /// Ctor is used implicitly by BENCHMARK_FUNC().
33 Function(const char *name
,
46 /// Get the name of this function
47 const char *GetName() const { return m_name
; }
49 /// Perform once-only initialization prior to Run().
50 bool Init() { return m_init
? (*m_init
)() : true; }
52 /// Run the function, return its return value.
53 bool Run() { return (*m_func
)(); }
55 /// Clean up after performing the benchmark.
56 void Done() { if ( m_done
) (*m_done
)(); }
58 /// Get the head of the linked list of benchmark objects
59 static Function
*GetFirst() { return ms_head
; }
61 /// Get the next object in the linked list or NULL
62 Function
*GetNext() const { return m_next
; }
65 // the head of the linked list of Bench::Function objects
66 static Function
*ms_head
;
68 // name of and pointer to the function, as passed to the ctor
69 const char * const m_name
;
70 const FuncType m_func
;
71 const InitType m_init
;
72 const DoneType m_done
;
74 // pointer to the next object in the linked list or NULL
75 Function
* const m_next
;
77 DECLARE_NO_COPY_CLASS(Function
)
81 Get the numeric parameter.
83 Tests may use this parameter in whatever way they see fit, by default it is
84 1 but can be set to a different value by user from the command line.
86 long GetNumericParameter();
89 Get the string parameter.
91 Tests may use this parameter in whatever way they see fit, by default it is
92 empty but can be set to a different value by user from the command line.
94 wxString
GetStringParameter();
99 This macro defines a benchmark function.
101 All these functions return a boolean value and take no parameters. The
102 return value is needed to prevent the compiler from optimizing the
103 benchmark entirely away and so typically will be constructed using the
104 results of the benchmark actions, even though normally benchmark should
107 Once benchmark is defined, it can be invoked from the command line of the
108 main benchmarking program.
110 #define BENCHMARK_FUNC(name) \
111 static bool name(); \
112 static Bench::Function wxMAKE_UNIQUE_NAME(name)(#name, name); \
116 Define a benchmark function requiring initialization and shutdown.
118 This macro is similar to BENCHMARK_FUNC() but ensures that @a init is
119 called before the benchmark is ran and @a done afterwards.
121 #define BENCHMARK_FUNC_WITH_INIT(name, init, done) \
122 static bool name(); \
123 static Bench::Function wxMAKE_UNIQUE_NAME(name)(#name, name, init, done); \
126 #endif // _WX_TESTS_BENCHMARKS_BENCH_H_