RISA
performance.h
Go to the documentation of this file.
1 /*
2  * This file is part of the RISA-library.
3  *
4  * Copyright (C) 2016 Helmholtz-Zentrum Dresden-Rossendorf
5  *
6  * RISA is free software: You can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * RISA is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with RISA. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Date: 30 November 2016
20  * Authors: Tobias Frust <t.frust@hzdr.de>
21  *
22  */
23 
24 #ifndef PERFORMANCE_H_
25 #define PERFORMANCE_H_
26 
27 #include <chrono>
28 
29 namespace risa {
30 
32 
36 class Timer {
37 
38 public:
39  Timer() {
40  }
41 
43  void start() {
44  beg_ = clock_::now();
45  }
46 
48  void stop() {
49  end_ = clock_::now();
50  }
51 
53 
56  double elapsed() const {
57  return std::chrono::duration_cast < second_ > (end_ - beg_).count();
58  }
59 
60 private:
61  typedef std::chrono::high_resolution_clock clock_;
62  typedef std::chrono::duration<double, std::ratio<1> > second_;
63  std::chrono::time_point<clock_> beg_;
64  std::chrono::time_point<clock_> end_;
65 };
66 
67 }
68 
69 #endif /* PERFORMANCE_H_ */
double elapsed() const
Computes the elapsed time between start() and stop()
Definition: performance.h:56
std::chrono::time_point< clock_ > end_
stores the end time point
Definition: performance.h:64
std::chrono::duration< double, std::ratio< 1 > > second_
Definition: performance.h:62
void start()
Start the time duration measurement.
Definition: performance.h:43
std::chrono::time_point< clock_ > beg_
stores the beginning point
Definition: performance.h:63
std::chrono::high_resolution_clock clock_
Definition: performance.h:61
The Timer-class uses the std::chrono library and provides a high precision timer. ...
Definition: performance.h:36
void stop()
Stop the time duration measurement.
Definition: performance.h:48