@@ -59,11 +59,12 @@ impl<'a> Benchmark<'a> {
59
59
command : & Command < ' _ > ,
60
60
error_output : & ' static str ,
61
61
output_policy : & CommandOutputPolicy ,
62
+ iteration : & executor:: BenchmarkIteration ,
62
63
) -> Result < TimingResult > {
63
64
self . executor
64
65
. run_command_and_measure (
65
66
command,
66
- executor :: BenchmarkIteration :: NonBenchmarkRun ,
67
+ iteration ,
67
68
Some ( CmdFailureAction :: RaiseError ) ,
68
69
output_policy,
69
70
)
@@ -76,6 +77,7 @@ impl<'a> Benchmark<'a> {
76
77
& self ,
77
78
parameters : impl IntoIterator < Item = ParameterNameAndValue < ' a > > ,
78
79
output_policy : & CommandOutputPolicy ,
80
+ iteration : executor:: BenchmarkIteration ,
79
81
) -> Result < TimingResult > {
80
82
let command = self
81
83
. options
@@ -87,7 +89,7 @@ impl<'a> Benchmark<'a> {
87
89
Append ' || true' to the command if you are sure that this can be ignored.";
88
90
89
91
Ok ( command
90
- . map ( |cmd| self . run_intermediate_command ( & cmd, error_output, output_policy) )
92
+ . map ( |cmd| self . run_intermediate_command ( & cmd, error_output, output_policy, & iteration ) )
91
93
. transpose ( ) ?
92
94
. unwrap_or_default ( ) )
93
95
}
@@ -97,6 +99,7 @@ impl<'a> Benchmark<'a> {
97
99
& self ,
98
100
parameters : impl IntoIterator < Item = ParameterNameAndValue < ' a > > ,
99
101
output_policy : & CommandOutputPolicy ,
102
+ iteration : executor:: BenchmarkIteration ,
100
103
) -> Result < TimingResult > {
101
104
let command = self
102
105
. options
@@ -108,7 +111,7 @@ impl<'a> Benchmark<'a> {
108
111
Append ' || true' to the command if you are sure that this can be ignored.";
109
112
110
113
Ok ( command
111
- . map ( |cmd| self . run_intermediate_command ( & cmd, error_output, output_policy) )
114
+ . map ( |cmd| self . run_intermediate_command ( & cmd, error_output, output_policy, & iteration ) )
112
115
. transpose ( ) ?
113
116
. unwrap_or_default ( ) )
114
117
}
@@ -118,23 +121,25 @@ impl<'a> Benchmark<'a> {
118
121
& self ,
119
122
command : & Command < ' _ > ,
120
123
output_policy : & CommandOutputPolicy ,
124
+ iteration : & executor:: BenchmarkIteration ,
121
125
) -> Result < TimingResult > {
122
126
let error_output = "The preparation command terminated with a non-zero exit code. \
123
127
Append ' || true' to the command if you are sure that this can be ignored.";
124
128
125
- self . run_intermediate_command ( command, error_output, output_policy)
129
+ self . run_intermediate_command ( command, error_output, output_policy, iteration )
126
130
}
127
131
128
132
/// Run the command specified by `--conclude`.
129
133
fn run_conclusion_command (
130
134
& self ,
131
135
command : & Command < ' _ > ,
132
136
output_policy : & CommandOutputPolicy ,
137
+ iteration : executor:: BenchmarkIteration ,
133
138
) -> Result < TimingResult > {
134
139
let error_output = "The conclusion command terminated with a non-zero exit code. \
135
140
Append ' || true' to the command if you are sure that this can be ignored.";
136
141
137
- self . run_intermediate_command ( command, error_output, output_policy)
142
+ self . run_intermediate_command ( command, error_output, output_policy, & iteration )
138
143
}
139
144
140
145
/// Run the benchmark for a single command
@@ -170,10 +175,10 @@ impl<'a> Benchmark<'a> {
170
175
)
171
176
} ) ;
172
177
173
- let run_preparation_command = || {
178
+ let run_preparation_command = |iteration : & executor :: BenchmarkIteration | {
174
179
preparation_command
175
180
. as_ref ( )
176
- . map ( |cmd| self . run_preparation_command ( cmd, output_policy) )
181
+ . map ( |cmd| self . run_preparation_command ( cmd, output_policy, iteration ) )
177
182
. transpose ( )
178
183
} ;
179
184
@@ -189,14 +194,18 @@ impl<'a> Benchmark<'a> {
189
194
self . command . get_parameters ( ) . iter ( ) . cloned ( ) ,
190
195
)
191
196
} ) ;
192
- let run_conclusion_command = || {
197
+ let run_conclusion_command = |iteration : executor :: BenchmarkIteration | {
193
198
conclusion_command
194
199
. as_ref ( )
195
- . map ( |cmd| self . run_conclusion_command ( cmd, output_policy) )
200
+ . map ( |cmd| self . run_conclusion_command ( cmd, output_policy, iteration ) )
196
201
. transpose ( )
197
202
} ;
198
203
199
- self . run_setup_command ( self . command . get_parameters ( ) . iter ( ) . cloned ( ) , output_policy) ?;
204
+ self . run_setup_command (
205
+ self . command . get_parameters ( ) . iter ( ) . cloned ( ) ,
206
+ output_policy,
207
+ executor:: BenchmarkIteration :: NonBenchmarkRun ,
208
+ ) ?;
200
209
201
210
// Warmup phase
202
211
if self . options . warmup_count > 0 {
@@ -211,14 +220,15 @@ impl<'a> Benchmark<'a> {
211
220
} ;
212
221
213
222
for i in 0 ..self . options . warmup_count {
214
- let _ = run_preparation_command ( ) ?;
223
+ let warmup_iteration = BenchmarkIteration :: Warmup ( i) ;
224
+ let _ = run_preparation_command ( & warmup_iteration) ?;
215
225
let _ = self . executor . run_command_and_measure (
216
226
self . command ,
217
- BenchmarkIteration :: Warmup ( i ) ,
227
+ & warmup_iteration ,
218
228
None ,
219
229
output_policy,
220
230
) ?;
221
- let _ = run_conclusion_command ( ) ?;
231
+ let _ = run_conclusion_command ( warmup_iteration ) ?;
222
232
if let Some ( bar) = progress_bar. as_ref ( ) {
223
233
bar. inc ( 1 )
224
234
}
@@ -239,20 +249,21 @@ impl<'a> Benchmark<'a> {
239
249
None
240
250
} ;
241
251
242
- let preparation_result = run_preparation_command ( ) ?;
252
+ let benchmark_iteration = BenchmarkIteration :: Benchmark ( 0 ) ;
253
+ let preparation_result = run_preparation_command ( & benchmark_iteration) ?;
243
254
let preparation_overhead =
244
255
preparation_result. map_or ( 0.0 , |res| res. time_real + self . executor . time_overhead ( ) ) ;
245
256
246
257
// Initial timing run
247
258
let ( res, status) = self . executor . run_command_and_measure (
248
259
self . command ,
249
- BenchmarkIteration :: Benchmark ( 0 ) ,
260
+ & benchmark_iteration ,
250
261
None ,
251
262
output_policy,
252
263
) ?;
253
264
let success = status. success ( ) ;
254
265
255
- let conclusion_result = run_conclusion_command ( ) ?;
266
+ let conclusion_result = run_conclusion_command ( benchmark_iteration ) ?;
256
267
let conclusion_overhead =
257
268
conclusion_result. map_or ( 0.0 , |res| res. time_real + self . executor . time_overhead ( ) ) ;
258
269
@@ -295,7 +306,8 @@ impl<'a> Benchmark<'a> {
295
306
296
307
// Gather statistics (perform the actual benchmark)
297
308
for i in 0 ..count_remaining {
298
- run_preparation_command ( ) ?;
309
+ let benchmark_iteration = BenchmarkIteration :: Benchmark ( i + 1 ) ;
310
+ run_preparation_command ( & benchmark_iteration) ?;
299
311
300
312
let msg = {
301
313
let mean = format_duration ( mean ( & times_real) , self . options . time_unit ) ;
@@ -308,7 +320,7 @@ impl<'a> Benchmark<'a> {
308
320
309
321
let ( res, status) = self . executor . run_command_and_measure (
310
322
self . command ,
311
- BenchmarkIteration :: Benchmark ( i + 1 ) ,
323
+ & benchmark_iteration ,
312
324
None ,
313
325
output_policy,
314
326
) ?;
@@ -326,7 +338,7 @@ impl<'a> Benchmark<'a> {
326
338
bar. inc ( 1 )
327
339
}
328
340
329
- run_conclusion_command ( ) ?;
341
+ run_conclusion_command ( benchmark_iteration ) ?;
330
342
}
331
343
332
344
if let Some ( bar) = progress_bar. as_ref ( ) {
@@ -441,7 +453,11 @@ impl<'a> Benchmark<'a> {
441
453
println ! ( " " ) ;
442
454
}
443
455
444
- self . run_cleanup_command ( self . command . get_parameters ( ) . iter ( ) . cloned ( ) , output_policy) ?;
456
+ self . run_cleanup_command (
457
+ self . command . get_parameters ( ) . iter ( ) . cloned ( ) ,
458
+ output_policy,
459
+ executor:: BenchmarkIteration :: NonBenchmarkRun ,
460
+ ) ?;
445
461
446
462
Ok ( BenchmarkResult {
447
463
command : self . command . get_name ( ) ,
0 commit comments