aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd/timer.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-11-12 01:23:55 +0000
committerlloyd <[email protected]>2014-11-12 01:23:55 +0000
commit8b0cbccc7b11e545ed27bc6d7bda04b5cf632e60 (patch)
tree7ea9368d6ccaa85337a63b55e8bd15efa46fd357 /src/cmd/timer.h
parent67161b91163afad417f9483cb557b26c5f5f4bc0 (diff)
Command line prog cleanup
Diffstat (limited to 'src/cmd/timer.h')
-rw-r--r--src/cmd/timer.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/cmd/timer.h b/src/cmd/timer.h
new file mode 100644
index 000000000..8e3dc6b26
--- /dev/null
+++ b/src/cmd/timer.h
@@ -0,0 +1,50 @@
+
+#ifndef BOTAN_BENCHMARK_TIMER_H__
+#define BOTAN_BENCHMARK_TIMER_H__
+
+#include <botan/types.h>
+#include <ostream>
+#include <string>
+
+using Botan::u64bit;
+using Botan::u32bit;
+
+class Timer
+ {
+ public:
+ static u64bit get_clock();
+
+ Timer(const std::string& name, u32bit event_mult = 1) :
+ m_name(name), m_event_mult(event_mult) {}
+
+ void start();
+ void stop();
+
+ u64bit value() { stop(); return m_time_used; }
+ double seconds() { return milliseconds() / 1000.0; }
+ double milliseconds() { return value() / 1000000.0; }
+
+ double ms_per_event() { return milliseconds() / events(); }
+ double seconds_per_event() { return seconds() / events(); }
+
+ u64bit events() const { return m_event_count * m_event_mult; }
+ std::string get_name() const { return m_name; }
+ private:
+ std::string m_name;
+ u64bit m_time_used = 0, m_timer_start = 0;
+ u64bit m_event_count = 0, m_event_mult = 0;
+ };
+
+inline bool operator<(const Timer& x, const Timer& y)
+ {
+ return (x.get_name() < y.get_name());
+ }
+
+inline bool operator==(const Timer& x, const Timer& y)
+ {
+ return (x.get_name() == y.get_name());
+ }
+
+std::ostream& operator<<(std::ostream&, Timer&);
+
+#endif