diff options
author | John Wiegley <johnw@newartisans.com> | 2004-11-08 06:43:11 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 02:40:47 -0400 |
commit | c9fb11bd60a2170fb896d77ff8d7706f563ad597 (patch) | |
tree | 42bdf09e7d8727ba31d1d8dae9b4eb4b2a605441 /timing.h | |
parent | fa2ceaed13c031add578ee8eb33da0c9980b9fb1 (diff) | |
download | fork-ledger-c9fb11bd60a2170fb896d77ff8d7706f563ad597.tar.gz fork-ledger-c9fb11bd60a2170fb896d77ff8d7706f563ad597.tar.bz2 fork-ledger-c9fb11bd60a2170fb896d77ff8d7706f563ad597.zip |
updated to version 2.0
Diffstat (limited to 'timing.h')
-rw-r--r-- | timing.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/timing.h b/timing.h new file mode 100644 index 00000000..bc7fdfe2 --- /dev/null +++ b/timing.h @@ -0,0 +1,54 @@ +#ifndef _TIMING_H +#define _TIMING_H + +#include "debug.h" + +#include <ctime> + +namespace ledger { + +class timing_t +{ + public: + std::clock_t begin; + std::clock_t cumulative; + std::string file; + unsigned long line; + std::string symbol; + std::string category; + + timing_t(const std::string& _symbol, const std::string& _category) + : begin(0), cumulative(0), symbol(_symbol), category(_category) {} + + ~timing_t() { + std::string cls = "timing.results."; + cls += symbol; + DEBUG_PRINT(cls.c_str(), file << ":" << line << ": " + << category << " = " + << (double(cumulative) / double(CLOCKS_PER_SEC)) << "s"); + } + + void start(const std::string& _file, unsigned long _line) { + file = _file; + line = _line; + begin = std::clock(); + } + + void stop() { + cumulative += std::clock() - begin; + } +}; + +#ifdef DEBUG_ENABLED +#define TIMER_DEF(sym, cat) static timing_t sym(#sym, cat) +#define TIMER_START(sym) sym.start(__FILE__, __LINE__) +#define TIMER_STOP(sym) sym.stop() +#else +#define TIMER_DEF(sym, cat) +#define TIMER_START(sym) +#define TIMER_STOP(sym) +#endif + +} // namespace ledger + +#endif // _TIMING_H |