]>
Commit | Line | Data |
---|---|---|
dc2ae355 VZ |
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" | |
49f11e84 | 15 | #include "wx/defs.h" |
dc2ae355 VZ |
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 | } // namespace Bench | |
67 | ||
68 | /** | |
69 | This macro defines a benchmark function. | |
70 | ||
71 | All these functions return a boolean value and take no parameters. The | |
72 | return value is needed to prevent the compiler from optimizing the | |
73 | benchmark entirely away and so typically will be constructed using the | |
74 | results of the benchmark actions, even though normally benchmark should | |
75 | always return true. | |
76 | ||
77 | Once benchmark is defined, it can be invoked from the command line of the | |
78 | main benchmarking program. | |
79 | */ | |
80 | #define BENCHMARK_FUNC(name) \ | |
81 | static bool name(); \ | |
82 | static Bench::Function wxMAKE_UNIQUE_NAME(name)(#name, name); \ | |
83 | bool name() | |
84 | ||
85 | #endif // _WX_TESTS_BENCHMARKS_BENCH_H_ |