-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_stopwatch.hpp
More file actions
75 lines (62 loc) · 2.03 KB
/
simple_stopwatch.hpp
File metadata and controls
75 lines (62 loc) · 2.03 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// simple_stopwatch.hpp
// ------------------------------------------------------------
#ifndef SIMPLE_STOPWATCH_HPP
#define SIMPLE_STOPWATCH_HPP
#define BOOST_CHRONO_VERSION 2
#define BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING 1
#include <ctime>
#include <boost/chrono/chrono_io.hpp>
#include "boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp"
#include "boost/chrono/stopwatches/reporters/system_default_formatter.hpp"
#include "boost/chrono/stopwatches/simple_stopwatch.hpp"
#include "boost/chrono/stopwatches/strict_stopwatch.hpp"
typedef boost::chrono::high_resolution_clock Clock;
namespace simple
{
////////////////////////////////////////////////////////////////////////////////////////////////
// NOTE: non portable! CK
// class Stopwatch {
// public:
// typedef long long rep;
//
// static rep now()
// {
// timespec ts;
// if (clock_gettime(CLOCK_MONOTONIC, &ts)) abort();
// return ts.tv_sec * rep(1000000000) + ts.tv_nsec;
// }
//
// Stopwatch()
// : start_(now())
// {}
//
// rep elapsed() const { return now() - start_; }
//
// private:
// rep start_;
// };
////////////////////////////////////////////////////////////////////////////////////////////////
template <class Clock> class simple_stopwatch {
typename Clock::time_point start;
public:
typedef long long rep;
simple_stopwatch()
: start(Clock::now())
{ }
typename Clock::duration elapsed() const { return Clock::now() - start; }
rep seconds() const
{
return elapsed().count()
* (static_cast<rep>(Clock::period::num) / Clock::period::den);
}
};
typedef simple_stopwatch<Clock> SimpleStopwatch;
} // namespace simple
typedef boost::chrono::strict_stopwatch<> StrictStopwatch;
typedef boost::chrono::simple_stopwatch<> Stopwatch;
typedef boost::chrono::stopwatch_reporter<Stopwatch> StopwatchReporter;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef boost::chrono::milliseconds ms;
typedef boost::chrono::nanoseconds ns;
#endif