server/UtDynamicsSimulator/TimeMeasure.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * The University of Tokyo
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  * General Robotix Inc.
10  */
11 
12 #ifndef OPENHRP_TIME_MEASURE_H_INCLUDED
13 #define OPENHRP_TIME_MEASURE_H_INCLUDED
14 
15 
16 #ifndef __WIN32__
17 
18 #include <sys/time.h>
19 
20 class TimeMeasure
21 {
22  struct timeval tv;
23  double time_;
24  double totalTime_;
25  int numCalls;
26 
27  public:
29  totalTime_ = 0.0;
30  numCalls = 0;
31  }
32 
33  void begin() {
34  gettimeofday(&tv, 0);
35  }
36 
37  void end(){
38  double beginTime = tv.tv_sec + (double)tv.tv_usec * 1.0e-6;
39  gettimeofday(&tv, 0);
40  double endTime = tv.tv_sec + (double)tv.tv_usec * 1.0e-6;
41  time_ = endTime - beginTime;
42  totalTime_ += time_;
43  numCalls++;
44  }
45 
46  double time() { return time_; }
47  double totalTime() { return totalTime_; }
48  double avarageTime() { return totalTime_ / numCalls; }
49 
50 };
51 
52 
53 #else
54 
55 class TimeMeasure
56 {
57  public:
58  TimeMeasure() { }
59  void begin() { }
60  void end(){ }
61  double time() { return 0.0; }
62  double totalTime() { return 0.0; }
63  double avarageTime() { return 0.0; }
64 };
65 
66 #endif
67 
68 
69 #endif
TimeMeasure::tv
struct timeval tv
Definition: hrplib/hrpUtil/TimeMeasure.h:20
TimeMeasure::TimeMeasure
TimeMeasure()
Definition: server/UtDynamicsSimulator/TimeMeasure.h:28
TimeMeasure::begin
void begin()
Definition: server/UtDynamicsSimulator/TimeMeasure.h:33
TimeMeasure::time
double time()
Definition: server/UtDynamicsSimulator/TimeMeasure.h:46
TimeMeasure::totalTime
double totalTime()
Definition: server/UtDynamicsSimulator/TimeMeasure.h:47
TimeMeasure::avarageTime
double avarageTime()
Definition: server/UtDynamicsSimulator/TimeMeasure.h:48
TimeMeasure::time
double time() const
Definition: hrplib/hrpUtil/TimeMeasure.h:47
TimeMeasure::totalTime_
double totalTime_
Definition: hrplib/hrpUtil/TimeMeasure.h:23
TimeMeasure::end
void end()
Definition: server/UtDynamicsSimulator/TimeMeasure.h:37
TimeMeasure
Definition: hrplib/hrpUtil/TimeMeasure.h:18
TimeMeasure::totalTime
double totalTime() const
Definition: hrplib/hrpUtil/TimeMeasure.h:48
TimeMeasure::numCalls
int numCalls
Definition: server/UtDynamicsSimulator/TimeMeasure.h:25
TimeMeasure::time_
double time_
Definition: hrplib/hrpUtil/TimeMeasure.h:21


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Wed Sep 7 2022 02:51:04