langpackedit: sorting fixes, 0.015 -- from 8f06f769
[wdl.git] / WDL / timing2.h
blob91240ffb28034af87bf8e832f9ddf60ff957e06b
1 #ifndef _WDL_TIMING2_H_
2 #define _WDL_TIMING2_H_
4 #if defined(_DEBUG) || defined(WDL_TIMING_ENABLE_FOR_RELEASE)
5 #include "time_precise.h"
6 #endif
8 class wdl_timing_accumulator
10 public:
12 #if defined(_DEBUG) || defined(WDL_TIMING_ENABLE_FOR_RELEASE)
14 wdl_timing_accumulator(const char *name=NULL)
16 m_cnt=0;
17 m_tot=m_cur=0.0;
18 m_name = name ? name : "[unnamed]";
19 m_depth = 0;
21 ~wdl_timing_accumulator()
23 Report("final");
26 void Report(const char *caption=NULL) const
28 if (m_cnt)
30 const double usec=1000000.0;
31 wdl_log_force("timing %s%s%s%s: %.0f calls, %.0f usec/call, %.0f usec total\n",
32 m_name, caption ? " (" : "", caption ? caption : "", caption ? ")" : "",
33 (double)m_cnt, m_tot*usec/(double)m_cnt, m_tot*usec);
37 void Begin()
39 if (!m_depth++)
40 m_cur = time_precise();
42 void End()
44 WDL_ASSERT(m_depth > 0);
45 if (!--m_depth)
47 WDL_ASSERT(m_cur != 0.0);
48 m_tot += time_precise()-m_cur;
49 m_cur=0.0;
50 m_cnt++;
54 private:
55 WDL_INT64 m_cnt;
56 double m_tot, m_cur;
57 const char *m_name;
58 int m_depth;
59 #else
61 wdl_timing_accumulator(const char *name=NULL) {}
62 ~wdl_timing_accumulator() {}
63 void Report(const char *caption=NULL) {}
64 void Begin() {}
65 void End() {}
67 #endif
70 class wdl_timing_accumulator_hold
72 public:
73 #if defined(_DEBUG) || defined(WDL_TIMING_ENABLE_FOR_RELEASE)
74 wdl_timing_accumulator_hold(wdl_timing_accumulator *p) : m_p(p) { if (p) p->Begin(); }
75 ~wdl_timing_accumulator_hold() { if (m_p) m_p->End(); }
76 wdl_timing_accumulator *m_p;
77 #else
78 wdl_timing_accumulator_hold(wdl_timing_accumulator *p) {}
79 #endif
82 #endif