@@ -293,6 +293,7 @@ struct Benchmark::Instance {
293
293
bool use_manual_time;
294
294
BigO complexity;
295
295
bool last_benchmark_instance;
296
+ int repetitions;
296
297
double min_time;
297
298
int threads; // Number of concurrent threads to use
298
299
bool multithreaded; // Is benchmark multi-threaded?
@@ -332,6 +333,7 @@ class BenchmarkImp {
332
333
void RangePair (int lo1, int hi1, int lo2, int hi2);
333
334
void RangeMultiplier (int multiplier);
334
335
void MinTime (double n);
336
+ void Repetitions (int n);
335
337
void UseRealTime ();
336
338
void UseManualTime ();
337
339
void Complexity (BigO complexity);
@@ -351,6 +353,7 @@ class BenchmarkImp {
351
353
TimeUnit time_unit_;
352
354
int range_multiplier_;
353
355
double min_time_;
356
+ int repetitions_;
354
357
bool use_real_time_;
355
358
bool use_manual_time_;
356
359
BigO complexity_;
@@ -414,6 +417,7 @@ bool BenchmarkFamilies::FindBenchmarks(
414
417
instance.time_unit = family->time_unit_ ;
415
418
instance.range_multiplier = family->range_multiplier_ ;
416
419
instance.min_time = family->min_time_ ;
420
+ instance.repetitions = family->repetitions_ ;
417
421
instance.use_real_time = family->use_real_time_ ;
418
422
instance.use_manual_time = family->use_manual_time_ ;
419
423
instance.complexity = family->complexity_ ;
@@ -430,6 +434,9 @@ bool BenchmarkFamilies::FindBenchmarks(
430
434
if (!IsZero (family->min_time_ )) {
431
435
instance.name += StringPrintF (" /min_time:%0.3f" , family->min_time_ );
432
436
}
437
+ if (family->repetitions_ != 0 ) {
438
+ instance.name += StringPrintF (" /repeats:%d" , family->repetitions_ );
439
+ }
433
440
if (family->use_manual_time_ ) {
434
441
instance.name += " /manual_time" ;
435
442
} else if (family->use_real_time_ ) {
@@ -453,7 +460,7 @@ bool BenchmarkFamilies::FindBenchmarks(
453
460
454
461
BenchmarkImp::BenchmarkImp (const char * name)
455
462
: name_(name), arg_count_(-1 ), time_unit_(kNanosecond ),
456
- range_multiplier_ (kRangeMultiplier ), min_time_(0.0 ),
463
+ range_multiplier_ (kRangeMultiplier ), min_time_(0.0 ), repetitions_( 0 ),
457
464
use_real_time_(false ), use_manual_time_(false ),
458
465
complexity_(oNone) {
459
466
}
@@ -521,6 +528,12 @@ void BenchmarkImp::MinTime(double t) {
521
528
min_time_ = t;
522
529
}
523
530
531
+
532
+ void BenchmarkImp::Repetitions (int n) {
533
+ CHECK (n > 0 );
534
+ repetitions_ = n;
535
+ }
536
+
524
537
void BenchmarkImp::UseRealTime () {
525
538
CHECK (!use_manual_time_) << " Cannot set UseRealTime and UseManualTime simultaneously." ;
526
539
use_real_time_ = true ;
@@ -633,6 +646,12 @@ Benchmark* Benchmark::RangeMultiplier(int multiplier) {
633
646
return this ;
634
647
}
635
648
649
+
650
+ Benchmark* Benchmark::Repetitions (int t) {
651
+ imp_->Repetitions (t);
652
+ return this ;
653
+ }
654
+
636
655
Benchmark* Benchmark::MinTime (double t) {
637
656
imp_->MinTime (t);
638
657
return this ;
@@ -712,7 +731,9 @@ void RunBenchmark(const benchmark::internal::Benchmark::Instance& b,
712
731
if (b.multithreaded )
713
732
pool.resize (b.threads );
714
733
715
- for (int i = 0 ; i < FLAGS_benchmark_repetitions; i++) {
734
+ const int repeats = b.repetitions != 0 ? b.repetitions
735
+ : FLAGS_benchmark_repetitions;
736
+ for (int i = 0 ; i < repeats; i++) {
716
737
std::string mem;
717
738
for (;;) {
718
739
// Try benchmark
@@ -893,12 +914,14 @@ void RunMatchingBenchmarks(const std::vector<Benchmark::Instance>& benchmarks,
893
914
CHECK (reporter != nullptr );
894
915
895
916
// Determine the width of the name field using a minimum width of 10.
917
+ bool has_repetitions = FLAGS_benchmark_repetitions > 1 ;
896
918
size_t name_field_width = 10 ;
897
919
for (const Benchmark::Instance& benchmark : benchmarks) {
898
920
name_field_width =
899
921
std::max<size_t >(name_field_width, benchmark.name .size ());
922
+ has_repetitions |= benchmark.repetitions > 1 ;
900
923
}
901
- if (FLAGS_benchmark_repetitions > 1 )
924
+ if (has_repetitions )
902
925
name_field_width += std::strlen (" _stddev" );
903
926
904
927
// Print header here
0 commit comments