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
double totalTime() const
double time() const
int gettimeofday(struct timeval *tv, struct timezone *tz)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:25