UTimer.cpp
Go to the documentation of this file.
1 /*
2 * utilite is a cross-platform library with
3 * useful utilities for fast and small developing.
4 * Copyright (C) 2010 Mathieu Labbe
5 *
6 * utilite is free library: 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 * utilite 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 this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "rtabmap/utilite/UTimer.h"
22 
24 // public:
27 {
28 #ifdef _WIN32
29  QueryPerformanceFrequency(&frequency_);
30 #endif
31  start(); // This will initialize the private counters
32 }
33 
35 
36 #ifdef _WIN32
37 double UTimer::now()
38 {
39  LARGE_INTEGER count, freq;
40  QueryPerformanceFrequency(&freq);
41  QueryPerformanceCounter(&count);
42  return double(count.QuadPart) / freq.QuadPart;
43 }
44 
45 void UTimer::start()
46 {
47  QueryPerformanceCounter(&startTimeRecorded_);
49 }
50 void UTimer::stop()
51 {
52  QueryPerformanceCounter(&stopTimeRecorded_);
53 
54 }
56 {
57  LARGE_INTEGER now;
58  QueryPerformanceCounter(&now);
59  return double(now.QuadPart - startTimeRecorded_.QuadPart) / frequency_.QuadPart;
60 }
61 double UTimer::getInterval()
62 {
63  if(stopTimeRecorded_.QuadPart == startTimeRecorded_.QuadPart)
64  {
65  return getElapsedTime();
66  }
67  else
68  {
69  return double(stopTimeRecorded_.QuadPart - startTimeRecorded_.QuadPart) / frequency_.QuadPart;
70  }
71 }
72 #else
73 double UTimer::now()
74 {
75  struct timeval tv;
76  gettimeofday(&tv, NULL);
77  return double(tv.tv_sec) + double(tv.tv_usec) / 1000000.0;
78 }
79 
81 {
82  gettimeofday(&startTimeRecorded_, NULL);
84 }
86 {
87  gettimeofday(&stopTimeRecorded_, NULL);
88 
89 }
91 {
92  return UTimer::now() - (double(startTimeRecorded_.tv_sec) + double(startTimeRecorded_.tv_usec) / 1000000.0);
93 
94 }
95 double UTimer::getInterval()
96 {
97  if(startTimeRecorded_.tv_sec == stopTimeRecorded_.tv_sec && startTimeRecorded_.tv_usec == stopTimeRecorded_.tv_usec)
98  {
99  return getElapsedTime();
100  }
101  else
102  {
103  double start = double(startTimeRecorded_.tv_sec) + double(startTimeRecorded_.tv_usec) / 1000000.0;
104  double stop = double(stopTimeRecorded_.tv_sec) + double(stopTimeRecorded_.tv_usec) / 1000000.0;
105  return stop - start;
106  }
107 }
108 #endif
109 
110 double UTimer::ticks() // Stop->start and return Interval
111 {
112  double inter = elapsed();
113  start();
114  return inter;
115 }
#define NULL
double elapsed()
Definition: UTimer.h:75
UTimer()
Definition: UTimer.cpp:26
struct timeval stopTimeRecorded_
Definition: UTimer.h:105
struct timeval startTimeRecorded_
Definition: UTimer.h:104
double getElapsedTime()
Definition: UTimer.cpp:90
~UTimer()
Definition: UTimer.cpp:34
void stop()
Definition: UTimer.cpp:85
void start()
Definition: UTimer.cpp:80
ULogger class and convenient macros.
double ticks()
Definition: UTimer.cpp:110
static double now()
Definition: UTimer.cpp:73


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:43:41