]> git.saurik.com Git - wxWidgets.git/blob - tests/benchmarks/bench.h
extact common GAddress declarations to the common header instead of duplicating them...
[wxWidgets.git] / tests / benchmarks / bench.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tests/benchmarks/bench.h
3 // Purpose: Main header of the benchmarking suite
4 // Author: Vadim Zeitlin
5 // Created: 2008-07-19
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_TESTS_BENCHMARKS_BENCH_H_
12 #define _WX_TESTS_BENCHMARKS_BENCH_H_
13
14 #include "wx/cpp.h"
15 #include "wx/defs.h"
16
17 namespace Bench
18 {
19
20 /**
21 Utility object used to register the benchmark functions.
22
23 @see BENCHMARK_FUNC
24 */
25 class Function
26 {
27 public:
28 typedef bool (*Type)();
29
30 /// Ctor is used implicitly by BENCHMARK_FUNC().
31 Function(const char *name, Type func)
32 : m_name(name),
33 m_func(func),
34 m_next(ms_head)
35 {
36 ms_head = this;
37 }
38
39 /// Get the name of this function
40 const char *GetName() const { return m_name; }
41
42 /// Run the function, return its return value.
43 bool Run() { return (*m_func)(); }
44
45
46 /// Get the head of the linked list of benchmark objects
47 static Function *GetFirst() { return ms_head; }
48
49 /// Get the next object in the linked list or NULL
50 Function *GetNext() const { return m_next; }
51
52 private:
53 // the head of the linked list of Bench::Function objects
54 static Function *ms_head;
55
56 // name of and pointer to the function, as passed to the ctor
57 const char * const m_name;
58 const Type m_func;
59
60 // pointer to the next object in the linked list or NULL
61 Function * const m_next;
62
63 DECLARE_NO_COPY_CLASS(Function)
64 };
65
66 /**
67 Get the numeric parameter.
68
69 Tests may use this parameter in whatever way they see fit, by default it is
70 1 but can be set to a different value by user from the command line.
71 */
72 long GetNumericParameter();
73
74 } // namespace Bench
75
76 /**
77 This macro defines a benchmark function.
78
79 All these functions return a boolean value and take no parameters. The
80 return value is needed to prevent the compiler from optimizing the
81 benchmark entirely away and so typically will be constructed using the
82 results of the benchmark actions, even though normally benchmark should
83 always return true.
84
85 Once benchmark is defined, it can be invoked from the command line of the
86 main benchmarking program.
87 */
88 #define BENCHMARK_FUNC(name) \
89 static bool name(); \
90 static Bench::Function wxMAKE_UNIQUE_NAME(name)(#name, name); \
91 bool name()
92
93 #endif // _WX_TESTS_BENCHMARKS_BENCH_H_