hrplib
hrpUtil
hrplib/hrpUtil/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
* National Institute of Advanced Industrial Science and Technology (AIST)
8
*/
9
10
#ifndef OPENHRP_UTIL_TIME_MEASURE_H_INCLUDED
11
#define OPENHRP_UTIL_TIME_MEASURE_H_INCLUDED
12
13
14
#ifndef __WIN32__
15
16
#include <sys/time.h>
17
18
class
TimeMeasure
19
{
20
struct
timeval
tv
;
21
double
time_
;
22
double
maxTime_
;
23
double
totalTime_
;
24
int
numCalls_
;
25
26
public
:
27
TimeMeasure
() {
28
totalTime_
= 0.0;
29
maxTime_
= 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
if (
time_
>
maxTime_
)
maxTime_
=
time_
;
43
totalTime_
+=
time_
;
44
numCalls_
++;
45
}
46
47
double
time
()
const
{
return
time_
; }
48
double
totalTime
()
const
{
return
totalTime_
; }
49
double
maxTime
()
const
{
return
maxTime_
; }
50
double
averageTime
()
const
{
return
totalTime_
/
numCalls_
; }
51
int
numCalls
()
const
{
return
numCalls_
; }
52
};
53
54
55
#else
56
#include <windows.h>
57
typedef
unsigned
__int64
ulonglong;
58
59
class
TimeMeasure
60
{
61
ulonglong iTimerScale;
62
ulonglong beginTime;
63
ulonglong endTime;
64
double
time_
;
65
double
maxTime_
;
66
double
totalTime_
;
67
int
numCalls_
;
68
69
public
:
70
TimeMeasure
() {
71
totalTime_
= 0.0;
72
maxTime_
= 0.0;
73
numCalls_
= 0;
74
BOOL
iDummyBool = QueryPerformanceFrequency ((LARGE_INTEGER *) &iTimerScale);
75
if
(!iDummyBool)
76
iTimerScale=1;
77
}
78
79
void
begin
() {
80
BOOL
iDummyBool = QueryPerformanceCounter ((LARGE_INTEGER *) &beginTime);
81
if
(!iDummyBool)
82
beginTime=1;
83
}
84
85
void
end
(){
86
BOOL
iDummyBool = QueryPerformanceCounter ((LARGE_INTEGER *) &endTime);
87
if
(!iDummyBool)
88
endTime=0;
89
time_
= (double)(endTime - beginTime) / iTimerScale;
90
if
(
time_
>
maxTime_
)
maxTime_
=
time_
;
91
totalTime_
+=
time_
;
92
numCalls_
++;
93
}
94
double
time
()
const
{
return
time_
; }
95
double
totalTime
()
const
{
return
totalTime_
; }
96
double
maxTime
()
const
{
return
maxTime_
; }
97
double
averageTime
()
const
{
return
totalTime_
/
numCalls_
; }
98
int
numCalls
()
const
{
return
numCalls_
; }
99
};
100
101
#endif
102
103
104
#endif
TimeMeasure::averageTime
double averageTime() const
Definition:
hrplib/hrpUtil/TimeMeasure.h:50
__int64
#define __int64
Definition:
Opcode.h:38
TimeMeasure::tv
struct timeval tv
Definition:
hrplib/hrpUtil/TimeMeasure.h:20
BOOL
int BOOL
Another boolean type.
Definition:
IceTypes.h:102
TimeMeasure::maxTime
double maxTime() const
Definition:
hrplib/hrpUtil/TimeMeasure.h:49
TimeMeasure::TimeMeasure
TimeMeasure()
Definition:
hrplib/hrpUtil/TimeMeasure.h:27
TimeMeasure::begin
void begin()
Definition:
hrplib/hrpUtil/TimeMeasure.h:33
TimeMeasure::maxTime_
double maxTime_
Definition:
hrplib/hrpUtil/TimeMeasure.h:22
TimeMeasure::numCalls
int numCalls() const
Definition:
hrplib/hrpUtil/TimeMeasure.h:51
TimeMeasure::time
double time() const
Definition:
hrplib/hrpUtil/TimeMeasure.h:47
TimeMeasure::numCalls_
int numCalls_
Definition:
hrplib/hrpUtil/TimeMeasure.h:24
TimeMeasure::totalTime_
double totalTime_
Definition:
hrplib/hrpUtil/TimeMeasure.h:23
TimeMeasure::end
void end()
Definition:
hrplib/hrpUtil/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