@@ -407,21 +407,20 @@ final class SampleRunner {
407
407
408
408
/// Invoke the benchmark entry point and return the run time in milliseconds.
409
409
func runBench( _ test: BenchmarkInfo , _ c: TestConfig ) -> BenchResults ? {
410
+ func logVerbose( _ msg: @autoclosure ( ) -> String ) {
411
+ if c. verbose { print ( msg ( ) ) }
412
+ }
410
413
var samples = [ Int] ( repeating: 0 , count: c. numSamples)
411
414
412
415
// Before we do anything, check that we actually have a function to
413
416
// run. If we don't it is because the benchmark is not supported on
414
417
// the platform and we should skip it.
415
418
guard let testFn = test. runFunction else {
416
- if c. verbose {
417
- print ( " Skipping unsupported benchmark \( test. name) ! " )
418
- }
419
+ logVerbose ( " Skipping unsupported benchmark \( test. name) ! " )
419
420
return nil
420
421
}
421
422
422
- if c. verbose {
423
- print ( " Running \( test. name) for \( c. numSamples) samples. " )
424
- }
423
+ logVerbose ( " Running \( test. name) for \( c. numSamples) samples. " )
425
424
426
425
let sampler = SampleRunner ( c)
427
426
test. setUpFunction ? ( )
@@ -438,9 +437,7 @@ func runBench(_ test: BenchmarkInfo, _ c: TestConfig) -> BenchResults? {
438
437
/// Number of iterations to make `testFn` run for the desired time.
439
438
scale = timePerSample / elapsed_time
440
439
} else {
441
- if c. verbose {
442
- print ( " Warning: elapsed time is 0. This can be safely ignored if the body is empty. " )
443
- }
440
+ logVerbose ( " Warning: elapsed time is 0! " )
444
441
scale = 1
445
442
}
446
443
} else {
@@ -457,16 +454,12 @@ func runBench(_ test: BenchmarkInfo, _ c: TestConfig) -> BenchResults? {
457
454
458
455
// Rerun the test with the computed scale factor.
459
456
if scale > 1 {
460
- if c. verbose {
461
- print ( " Measuring with scale \( scale) . " )
462
- }
457
+ logVerbose ( " Measuring with scale \( scale) . " )
463
458
elapsed_time = sampler. measure ( test. name, fn: testFn, numIters: scale)
464
459
}
465
460
466
461
samples [ s] = elapsed_time
467
- if c. verbose {
468
- print ( " Sample \( s) , \( samples [ s] ) " )
469
- }
462
+ logVerbose ( " Sample \( s) , \( samples [ s] ) " )
470
463
}
471
464
test. tearDownFunction ? ( )
472
465
0 commit comments