aboutsummaryrefslogtreecommitdiff
path: root/src/console_reporter.cc
diff options
context:
space:
mode:
authorKai Wolf <kai.wolf@gmail.com>2016-03-24 22:18:55 +0100
committerKai Wolf <kai.wolf@gmail.com>2016-03-24 22:18:55 +0100
commitcded70a1660e81f854b5d41795a514ec0825c32a (patch)
treed9d84f126f9e0b0b0bad309c21572fc29f698cd9 /src/console_reporter.cc
parentb2e734087532897b7bb4c51a6b4f503060c9a20f (diff)
downloadgoogle-benchmark-cded70a1660e81f854b5d41795a514ec0825c32a.tar.gz
Add optional ms time unit for console reporter
Some benchmarks may run a few milliseconds which makes it kind of hard to visually compare, since the currently only available nanoseconds numbers can get very large in this case. Therefore this commit adds an optional command line flag --benchmark_time_unit which lets the user choose between ns and ms time units for displaying the mean execution time.
Diffstat (limited to 'src/console_reporter.cc')
-rw-r--r--src/console_reporter.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/console_reporter.cc b/src/console_reporter.cc
index 092936d..6af5157 100644
--- a/src/console_reporter.cc
+++ b/src/console_reporter.cc
@@ -29,6 +29,7 @@ namespace benchmark {
bool ConsoleReporter::ReportContext(const Context& context) {
name_field_width_ = context.name_field_width;
+ time_unit_ = context.time_unit;
std::cerr << "Run on (" << context.num_cpus << " X " << context.mhz_per_cpu
<< " MHz CPU " << ((context.num_cpus > 1) ? "s" : "") << ")\n";
@@ -46,9 +47,11 @@ bool ConsoleReporter::ReportContext(const Context& context) {
"affected.\n";
#endif
+ std::string timeLabel = "Time(" + time_unit_ + ")";
+ std::string cpuLabel = "CPU(" + time_unit_ + ")";
int output_width = fprintf(stdout, "%-*s %10s %10s %10s\n",
static_cast<int>(name_field_width_), "Benchmark",
- "Time(ns)", "CPU(ns)", "Iterations");
+ timeLabel.c_str(), cpuLabel.c_str(), "Iterations");
std::cout << std::string(output_width - 1, '-') << "\n";
return true;
@@ -92,7 +95,9 @@ void ConsoleReporter::PrintRunData(const Run& result) {
" items/s");
}
- double const multiplier = 1e9; // nano second multiplier
+ double const multiplier = time_unit_ == "ns" ? 1e9 : 1e3; // nano second or
+ // millis multiplier
+
ColorPrintf(COLOR_GREEN, "%-*s ",
name_field_width_, result.benchmark_name.c_str());
if (result.iterations == 0) {