-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_timer.hpp
64 lines (55 loc) · 2.06 KB
/
test_timer.hpp
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
// This file is part of DSP library containing useful reusable
// signal processing utility classes.
//
// Copyright (C) 2018 Duncan Crutchley
// Contact <dac1976github@outlook.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License and GNU Lesser General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License
// and GNU Lesser General Public License along with this program. If
// not, see <http://www.gnu.org/licenses/>.
#ifndef TEST_TIMER_HPP
#define TEST_TIMER_HPP
#include <chrono>
/*! \brief namespace test */
namespace test
{
/*! \brief Timer class to help with test benchmarking.*/
class Timer final
{
/*! \brief Typedef to high resolution clock.*/
using high_res_clock_t = std::chrono::high_resolution_clock;
/*! \brief Typedef to high resolution clock time point.*/
using time_point_t = std::chrono::high_resolution_clock::time_point;
/*! \brief Typedef to timer duration.*/
using duration_t = std::chrono::duration<double>;
public:
/*!
* \brief Compute elapsed time of timer.
* \return Elapsed time of the timer as a double.
*/
double Elapsed() const
{
return std::chrono::duration_cast<duration_t>(high_res_clock_t::now() - m_begin).count();
}
/*! \brief Reset the timers start time point.*/
void Reset()
{
m_begin = high_res_clock_t::now();
}
private:
/*! \brief Initialise begin time point to now as soon as Timer is created.*/
time_point_t m_begin{high_res_clock_t::now()};
};
} // namespace test
#endif // TEST_TIMER_HPP