diff options
author | Elliott Hughes <enh@google.com> | 2014-06-11 16:48:29 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2014-06-11 16:48:29 -0700 |
commit | c0eed72cbfe29d7d5f7daea9d019982465c566f0 (patch) | |
tree | 54a71ad9fe4022d47d09695ab971c945f1ea868d /benchmarks | |
parent | 2c02d0057c93bfa6db4b30d8646baeb55d076062 (diff) | |
download | bionic-c0eed72cbfe29d7d5f7daea9d019982465c566f0.zip bionic-c0eed72cbfe29d7d5f7daea9d019982465c566f0.tar.gz bionic-c0eed72cbfe29d7d5f7daea9d019982465c566f0.tar.bz2 |
Size the benchmark name column appropriately.
Nobody likes misaligned output.
Change-Id: Ifbfd7beec755e91e204426a96c054d4ea20d3fae
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/benchmark_main.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/benchmarks/benchmark_main.cpp b/benchmarks/benchmark_main.cpp index f8e85bb..cd80968 100644 --- a/benchmarks/benchmark_main.cpp +++ b/benchmarks/benchmark_main.cpp @@ -32,6 +32,7 @@ static int64_t g_benchmark_start_time_ns; typedef std::map<std::string, ::testing::Benchmark*> BenchmarkMap; typedef BenchmarkMap::iterator BenchmarkMapIt; static BenchmarkMap g_benchmarks; +static size_t g_name_column_width = 20; static int Round(int n) { int base = 1; @@ -164,7 +165,7 @@ void Benchmark::RunWithArg(int arg) { snprintf(full_name, sizeof(full_name), "%s", name_); } - printf("%-20s %10d %10" PRId64 "%s\n", full_name, + printf("%-*s %10d %10" PRId64 "%s\n", g_name_column_width, full_name, iterations, g_benchmark_total_time_ns/iterations, throughput); fflush(stdout); } @@ -194,12 +195,16 @@ int main(int argc, char* argv[]) { exit(EXIT_FAILURE); } + for (BenchmarkMapIt it = g_benchmarks.begin(); it != g_benchmarks.end(); ++it) { + g_name_column_width = std::max(g_name_column_width, strlen(it->second->Name())); + } + bool need_header = true; for (BenchmarkMapIt it = g_benchmarks.begin(); it != g_benchmarks.end(); ++it) { ::testing::Benchmark* b = it->second; if (b->ShouldRun(argc, argv)) { if (need_header) { - printf("%-20s %10s %10s\n", "", "iterations", "ns/op"); + printf("%-*s %10s %10s\n", g_name_column_width, "", "iterations", "ns/op"); fflush(stdout); need_header = false; } |