@@ -71,6 +71,7 @@ class Timer_EXPORT Timer
71
71
protected:
72
72
73
73
struct timeval t0,t1;
74
+ clock_t c0, c1;
74
75
double dt;
75
76
76
77
public:
@@ -87,6 +88,7 @@ class Timer_EXPORT Timer
87
88
88
89
dg::SignalPtr<T,int > sigSIN;
89
90
dg::SignalTimeDependent<T,int > sigSOUT;
91
+ dg::SignalTimeDependent<T,int > sigClockSOUT;
90
92
dg::Signal<double ,int > timerSOUT;
91
93
92
94
@@ -96,18 +98,30 @@ class Timer_EXPORT Timer
96
98
sigSIN = &sig; dt=0 .;
97
99
}
98
100
101
+ template <bool UseClock>
99
102
T& compute ( T& t,const int & time )
100
103
{
101
104
sotDEBUGIN (15 );
102
- gettimeofday (&t0,NULL );
103
- sotDEBUG (15 ) << " t0: " << t0.tv_sec << " - " << t0.tv_usec << std::endl;
105
+ if (UseClock) {
106
+ c0 = clock ();
107
+ sotDEBUG (15 ) << " t0: " << c0 << std::endl;
108
+ } else {
109
+ gettimeofday (&t0,NULL );
110
+ sotDEBUG (15 ) << " t0: " << t0.tv_sec << " - " << t0.tv_usec << std::endl;
111
+ }
104
112
105
113
t = sigSIN ( time );
106
114
107
- gettimeofday (&t1,NULL );
108
- dt = ( (t1.tv_sec -t0.tv_sec ) * 1000 .
109
- + (t1.tv_usec -t0.tv_usec +0 .) / 1000 . );
110
- sotDEBUG (15 ) << " t1: " << t1.tv_sec << " - " << t1.tv_usec << std::endl;
115
+ if (UseClock) {
116
+ c1 = clock ();
117
+ sotDEBUG (15 ) << " t1: " << c0 << std::endl;
118
+ dt = ((double )(c1 - c0) * 1000 ) / CLOCKS_PER_SEC;
119
+ } else {
120
+ gettimeofday (&t1,NULL );
121
+ dt = ( (t1.tv_sec -t0.tv_sec ) * 1000 .
122
+ + (t1.tv_usec -t0.tv_usec +0 .) / 1000 . );
123
+ sotDEBUG (15 ) << " t1: " << t1.tv_sec << " - " << t1.tv_usec << std::endl;
124
+ }
111
125
112
126
timerSOUT = dt;
113
127
timerSOUT.setTime (time);
@@ -146,18 +160,20 @@ template< class T >
146
160
Timer<T>::
147
161
Timer ( const std::string& name )
148
162
:Entity(name)
149
- ,t0(),t1()
150
163
,dt(0 .)
151
164
,sigSIN( NULL ," Timer(" +name+" )::input(T)::sin" )
152
- ,sigSOUT( boost::bind(&Timer::compute,this ,_1,_2),
165
+ ,sigSOUT( boost::bind(&Timer::compute<false >,this ,_1,_2),
166
+ sigSIN,
167
+ "Timer(" +name+" )::output(T)::sout" )
168
+ ,sigClockSOUT( boost::bind(&Timer::compute<true >,this ,_1,_2),
153
169
sigSIN,
154
170
"Timer(" +name+" )::output(T)::sout" )
155
171
,timerSOUT( " Timer(" +name+" )::output(double)::timer" )
156
172
{
157
173
sotDEBUGIN (15 );
158
174
timerSOUT.setFunction ( boost::bind (&Timer::getDt,this ,_1,_2) );
159
175
160
- signalRegistration ( sigSIN<<sigSOUT<<timerSOUT );
176
+ signalRegistration ( sigSIN<<sigSOUT<<sigClockSOUT<< timerSOUT );
161
177
sotDEBUGOUT (15 );
162
178
}
163
179
0 commit comments