aboutsummaryrefslogtreecommitdiffstats
path: root/checks/timer.h
blob: 4bdc08154f524f5092d529105cd853955d9a0de6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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);

      void start();

      void stop();

      u64bit value() { stop(); return 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(); }

      u32bit events() const { return event_count * event_mult; }
      std::string get_name() const { return name; }
   private:
      std::string name;
      u64bit time_used, timer_start;
      u32bit event_count, event_mult;
   };

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