LBIBCell
 All Classes Functions Variables Friends Pages
Timer.hpp
1 /* Copyright (c) 2013 David Sichau <mail"at"sichau"dot"eu>
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18  * THE SOFTWARE.
19  *
20  */
21 
22 #ifndef UTILIB_TIMER_HPP_
23 #define UTILIB_TIMER_HPP_
24 
25 #pragma once
26 #include <sys/time.h>
27 
28 namespace UtilLib {
32 class Timer {
33  public:
37  void start() {
38  gettimeofday(&t_start, &t_zone);
39  }
40 
46  inline double stop() {
47  gettimeofday(&t_end, &t_zone);
48  return (t_end.tv_usec -
49  t_start.tv_usec) * 1e-6 + (t_end.tv_sec - t_start.tv_sec);
50  }
51 
52  private:
56  struct timeval t_start, t_end;
60  struct timezone t_zone;
61 };
62 } /* end namespace */
63 #endif /* UTILIB_TIMER_HPP_ */
a class for timing
Definition: Timer.hpp:32
void start()
starts the timer
Definition: Timer.hpp:37
double stop()
stops the timer and returns the time in sec
Definition: Timer.hpp:46