]> git.saurik.com Git - wxWidgets.git/blob - tests/benchmarks/log.cpp
Use wxCOMPtr throughout wxWebViewIE to simplify the code and reduce the chance of...
[wxWidgets.git] / tests / benchmarks / log.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tests/benchmarks/log.cpp
3 // Purpose: Log-related benchmarks
4 // Author: Vadim Zeitlin
5 // Created: 2012-01-21
6 // RCS-ID: $Id$
7 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "bench.h"
12
13 #include "wx/log.h"
14
15 // This class is used to check that the arguments of log functions are not
16 // evaluated.
17 struct NotCreated
18 {
19 NotCreated() { wxAbort(); }
20
21 const char* AsStr() const { return "unreachable"; }
22 };
23
24 // Temporarily change the log level to the given one.
25 class LogLevelSetter
26 {
27 public:
28 LogLevelSetter(wxLogLevel levelNew)
29 : m_levelOld(wxLog::GetLogLevel())
30 {
31 wxLog::SetLogLevel(levelNew);
32 }
33
34 ~LogLevelSetter()
35 {
36 wxLog::SetLogLevel(m_levelOld);
37 }
38
39 private:
40 const wxLogLevel m_levelOld;
41
42 wxDECLARE_NO_COPY_CLASS(LogLevelSetter);
43 };
44
45 BENCHMARK_FUNC(LogDebugDisabled)
46 {
47 LogLevelSetter level(wxLOG_Info);
48
49 wxLogDebug("Ignored debug message: %s", NotCreated().AsStr());
50
51 return true;
52 }
53
54 BENCHMARK_FUNC(LogTraceDisabled)
55 {
56 LogLevelSetter level(wxLOG_Info);
57
58 wxLogTrace("", NotCreated().AsStr());
59
60 return true;
61 }
62
63 BENCHMARK_FUNC(LogTraceActive)
64 {
65 static bool s_added = false;
66 if ( !s_added )
67 {
68 s_added = true;
69 wxLog::AddTraceMask("logbench");
70 }
71
72 // Remove the actual logging overhead by simply throwing away the log
73 // messages.
74 class NulLog : public wxLog
75 {
76 public:
77 NulLog()
78 : m_logOld(wxLog::SetActiveTarget(this))
79 {
80 }
81
82 virtual ~NulLog()
83 {
84 wxLog::SetActiveTarget(m_logOld);
85 }
86
87 protected:
88 virtual void DoLogRecord(wxLogLevel,
89 const wxString&,
90 const wxLogRecordInfo&)
91 {
92 }
93
94 wxLog* m_logOld;
95 };
96
97 NulLog nulLog;
98
99 wxLogTrace("logbench", "Trace message");
100
101 return true;
102 }
103
104 BENCHMARK_FUNC(LogTraceInactive)
105 {
106 wxLogTrace("bloordyblop", "Trace message");
107
108 return true;
109 }