| 304 | } |
| 305 | |
| 306 | void RunBenchmarks(const std::vector<BenchmarkInstance>& benchmarks, |
| 307 | BenchmarkReporter* display_reporter, |
| 308 | BenchmarkReporter* file_reporter) { |
| 309 | // Note the file_reporter can be null. |
| 310 | BM_CHECK(display_reporter != nullptr); |
| 311 | |
| 312 | // Determine the width of the name field using a minimum width of 10. |
| 313 | bool might_have_aggregates = FLAGS_benchmark_repetitions > 1; |
| 314 | size_t name_field_width = 10; |
| 315 | size_t stat_field_width = 0; |
| 316 | for (const BenchmarkInstance& benchmark : benchmarks) { |
| 317 | name_field_width = |
| 318 | std::max<size_t>(name_field_width, benchmark.name().str().size()); |
| 319 | might_have_aggregates |= benchmark.repetitions() > 1; |
| 320 | |
| 321 | for (const auto& Stat : benchmark.statistics()) |
| 322 | stat_field_width = std::max<size_t>(stat_field_width, Stat.name_.size()); |
| 323 | } |
| 324 | if (might_have_aggregates) name_field_width += 1 + stat_field_width; |
| 325 | |
| 326 | // Print header here |
| 327 | BenchmarkReporter::Context context; |
| 328 | context.name_field_width = name_field_width; |
| 329 | |
| 330 | // Keep track of running times of all instances of each benchmark family. |
| 331 | std::map<int /*family_index*/, BenchmarkReporter::PerFamilyRunReports> |
| 332 | per_family_reports; |
| 333 | |
| 334 | if (display_reporter->ReportContext(context) && |
| 335 | (!file_reporter || file_reporter->ReportContext(context))) { |
| 336 | FlushStreams(display_reporter); |
| 337 | FlushStreams(file_reporter); |
| 338 | |
| 339 | size_t num_repetitions_total = 0; |
| 340 | |
| 341 | std::vector<internal::BenchmarkRunner> runners; |
| 342 | runners.reserve(benchmarks.size()); |
| 343 | for (const BenchmarkInstance& benchmark : benchmarks) { |
| 344 | BenchmarkReporter::PerFamilyRunReports* reports_for_family = nullptr; |
| 345 | if (benchmark.complexity() != oNone) |
| 346 | reports_for_family = &per_family_reports[benchmark.family_index()]; |
| 347 | |
| 348 | runners.emplace_back(benchmark, reports_for_family); |
| 349 | int num_repeats_of_this_instance = runners.back().GetNumRepeats(); |
| 350 | num_repetitions_total += num_repeats_of_this_instance; |
| 351 | if (reports_for_family) |
| 352 | reports_for_family->num_runs_total += num_repeats_of_this_instance; |
| 353 | } |
| 354 | assert(runners.size() == benchmarks.size() && "Unexpected runner count."); |
| 355 | |
| 356 | std::vector<size_t> repetition_indices; |
| 357 | repetition_indices.reserve(num_repetitions_total); |
| 358 | for (size_t runner_index = 0, num_runners = runners.size(); |
| 359 | runner_index != num_runners; ++runner_index) { |
| 360 | const internal::BenchmarkRunner& runner = runners[runner_index]; |
| 361 | std::fill_n(std::back_inserter(repetition_indices), |
| 362 | runner.GetNumRepeats(), runner_index); |
| 363 | } |
no test coverage detected