]> git.saurik.com Git - wxWidgets.git/blob - tests/benchmarks/bench.h
pass asciistr, not utf8str, to FromAscii
[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
16 namespace Bench
17 {
18
19 /**
20 Utility object used to register the benchmark functions.
21
22 @see BENCHMARK_FUNC
23 */
24 class Function
25 {
26 public:
27 typedef bool (*Type)();
28
29 /// Ctor is used implicitly by BENCHMARK_FUNC().
30 Function(const char *name, Type func)
31 : m_name(name),
32 m_func(func),
33 m_next(ms_head)
34 {
35 ms_head = this;
36 }
37
38 /// Get the name of this function
39 const char *GetName() const { return m_name; }
40
41 /// Run the function, return its return value.
42 bool Run() { return (*m_func)(); }
43
44
45 /// Get the head of the linked list of benchmark objects
46 static Function *GetFirst() { return ms_head; }
47
48 /// Get the next object in the linked list or NULL
49 Function *GetNext() const { return m_next; }
50
51 private:
52 // the head of the linked list of Bench::Function objects
53 static Function *ms_head;
54
55 // name of and pointer to the function, as passed to the ctor
56 const char * const m_name;
57 const Type m_func;
58
59 // pointer to the next object in the linked list or NULL
60 Function * const m_next;
61
62 DECLARE_NO_COPY_CLASS(Function)
63 };
64
65 } // namespace Bench
66
67 /**
68 This macro defines a benchmark function.
69
70 All these functions return a boolean value and take no parameters. The
71 return value is needed to prevent the compiler from optimizing the
72 benchmark entirely away and so typically will be constructed using the
73 results of the benchmark actions, even though normally benchmark should
74 always return true.
75
76 Once benchmark is defined, it can be invoked from the command line of the
77 main benchmarking program.
78 */
79 #define BENCHMARK_FUNC(name) \
80 static bool name(); \
81 static Bench::Function wxMAKE_UNIQUE_NAME(name)(#name, name); \
82 bool name()
83
84 #endif // _WX_TESTS_BENCHMARKS_BENCH_H_