1
1
//! Counters for benchmarking various parts of the physics engine.
2
2
3
+ use core:: time:: Duration ;
3
4
use std:: fmt:: { Display , Formatter , Result } ;
4
5
5
6
pub use self :: ccd_counters:: CCDCounters ;
@@ -76,11 +77,16 @@ impl Counters {
76
77
}
77
78
}
78
79
79
- /// Total time spent for one of the physics engine.
80
- pub fn step_time ( & self ) -> f64 {
80
+ /// Total time spent for one of the physics engine.
81
+ pub fn step_time ( & self ) -> Duration {
81
82
self . step_time . time ( )
82
83
}
83
84
85
+ /// Total time spent for one of the physics engine, in milliseconds.
86
+ pub fn step_time_ms ( & self ) -> f64 {
87
+ self . step_time . time_ms ( )
88
+ }
89
+
84
90
/// Notify that the custom operation has started.
85
91
pub fn custom_started ( & mut self ) {
86
92
if self . enabled {
@@ -96,10 +102,15 @@ impl Counters {
96
102
}
97
103
98
104
/// Total time of a custom event.
99
- pub fn custom_time ( & self ) -> f64 {
105
+ pub fn custom_time ( & self ) -> Duration {
100
106
self . custom . time ( )
101
107
}
102
108
109
+ /// Total time of a custom event, in milliseconds.
110
+ pub fn custom_time_ms ( & self ) -> f64 {
111
+ self . custom . time_ms ( )
112
+ }
113
+
103
114
/// Set the number of constraints generated.
104
115
pub fn set_nconstraints ( & mut self , n : usize ) {
105
116
self . solver . nconstraints = n;
@@ -129,7 +140,7 @@ impl Counters {
129
140
}
130
141
131
142
macro_rules! measure_method {
132
- ( $started: ident, $stopped: ident, $time : ident, $info: ident. $timer: ident) => {
143
+ ( $started: ident, $stopped: ident, $time_ms : ident, $info: ident. $timer: ident) => {
133
144
impl Counters {
134
145
/// Start this timer.
135
146
pub fn $started( & mut self ) {
@@ -145,10 +156,10 @@ macro_rules! measure_method {
145
156
}
146
157
}
147
158
148
- /// Gets the time elapsed for this timer.
149
- pub fn $time ( & self ) -> f64 {
159
+ /// Gets the time elapsed for this timer, in milliseconds .
160
+ pub fn $time_ms ( & self ) -> f64 {
150
161
if self . enabled {
151
- self . $info. $timer. time ( )
162
+ self . $info. $timer. time_ms ( )
152
163
} else {
153
164
0.0
154
165
}
@@ -160,63 +171,63 @@ macro_rules! measure_method {
160
171
measure_method ! (
161
172
update_started,
162
173
update_completed,
163
- update_time ,
174
+ update_time_ms ,
164
175
stages. update_time
165
176
) ;
166
177
measure_method ! (
167
178
collision_detection_started,
168
179
collision_detection_completed,
169
- collision_detection_time ,
180
+ collision_detection_time_ms ,
170
181
stages. collision_detection_time
171
182
) ;
172
183
measure_method ! (
173
184
island_construction_started,
174
185
island_construction_completed,
175
- island_construction_time ,
186
+ island_construction_time_ms ,
176
187
stages. island_construction_time
177
188
) ;
178
189
measure_method ! (
179
190
solver_started,
180
191
solver_completed,
181
- solver_time ,
192
+ solver_time_ms ,
182
193
stages. solver_time
183
194
) ;
184
- measure_method ! ( ccd_started, ccd_completed, ccd_time , stages. ccd_time) ;
195
+ measure_method ! ( ccd_started, ccd_completed, ccd_time_ms , stages. ccd_time) ;
185
196
measure_method ! (
186
197
query_pipeline_update_started,
187
198
query_pipeline_update_completed,
188
- query_pipeline_update_time ,
199
+ query_pipeline_update_time_ms ,
189
200
stages. query_pipeline_time
190
201
) ;
191
202
192
203
measure_method ! (
193
204
assembly_started,
194
205
assembly_completed,
195
- assembly_time ,
206
+ assembly_time_ms ,
196
207
solver. velocity_assembly_time
197
208
) ;
198
209
measure_method ! (
199
210
velocity_resolution_started,
200
211
velocity_resolution_completed,
201
- velocity_resolution_time ,
212
+ velocity_resolution_time_ms ,
202
213
solver. velocity_resolution_time
203
214
) ;
204
215
measure_method ! (
205
216
velocity_update_started,
206
217
velocity_update_completed,
207
- velocity_update_time ,
218
+ velocity_update_time_ms ,
208
219
solver. velocity_update_time
209
220
) ;
210
221
measure_method ! (
211
222
broad_phase_started,
212
223
broad_phase_completed,
213
- broad_phase_time ,
224
+ broad_phase_time_ms ,
214
225
cd. broad_phase_time
215
226
) ;
216
227
measure_method ! (
217
228
narrow_phase_started,
218
229
narrow_phase_completed,
219
- narrow_phase_time ,
230
+ narrow_phase_time_ms ,
220
231
cd. narrow_phase_time
221
232
) ;
222
233
0 commit comments