10000 Merge cc13eea3c8cc1d8823bafc2b1e4830efd0e3ba93 into b1717916d1acafbd0… · google/benchmark@0ca09d3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 0ca09d3

Browse files
authored
Merge cc13eea into b171791
2 parents b171791 + cc13eea commit 0ca09d3

File tree

4 files changed

+40
-21
lines changed

4 files changed

+40
-21
lines changed

src/console_reporter.cc

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ bool ConsoleReporter::ReportContext(const Context& context) {
5353
}
5454

5555
void ConsoleReporter::PrintHeader(const Run& run) {
56-
std::string str = FormatString("%-*s %13s %13s %10s", static_cast<int>(name_field_width_),
56+
std::string str = FormatString("%-*s %13s %15s %12s", static_cast<int>(name_field_width_),
5757
"Benchmark", "Time", "CPU", "Iterations");
5858
if(!run.counters.empty()) {
5959
if(output_options_ & OO_Tabular) {
@@ -98,6 +98,21 @@ static void IgnoreColorPrint(std::ostream& out, LogColor, const char* fmt,
9898
va_end(args);
9999
}
100100

101+
102+
static std::string FormatTime(double time) {
103+
// Align decimal places...
104+
if (time < 1.0) {
105+
return FormatString("%10.3f", time);
106+
}
107+
if (time < 10.0) {
108+
return FormatString("%10.2f", time);
109+
}
110+
if (time < 100.0) {
111+
return FormatString("%10.1f", time);
112+
}
113+
return FormatString("%10.0f", time);
114+
}
115+
101116
void ConsoleReporter::PrintRunData(const Run& result) {
102117
typedef void(PrinterFn)(std::ostream&, LogColor, const char*, ...);
103118
auto& Out = GetOutputStream();
@@ -117,18 +132,21 @@ void ConsoleReporter::PrintRunData(const Run& result) {
117132

118133
const double real_time = result.GetAdjustedRealTime();
119134
const double cpu_time = result.GetAdjustedCPUTime();
135+
const std::string real_time_str = FormatTime(real_time);
136+
const std::string cpu_time_str = FormatTime(cpu_time);
137+
120138

121139
if (result.report_big_o) {
122140
std::string big_o = GetBigOString(result.complexity);
123-
printer(Out, COLOR_YELLOW, "%10.2f %s %10.2f %s ", real_time, big_o.c_str(),
141+
printer(Out, COLOR_YELLOW, "%10.2f %-4s %10.2f %-4s ", real_time, big_o.c_str(),
124142
cpu_time, big_o.c_str());
125143
} else if (result.report_rms) {
126-
printer(Out, COLOR_YELLOW, "%10.0f %% %10.0f %% ", real_time * 100,
127-
cpu_time * 100);
144+
printer(Out, COLOR_YELLOW, "%10.0f %-4s %10.0f %-4s ", real_time * 100, "%",
145+
cpu_time * 100, "%");
128146
} else {
129147
const char* timeLabel = GetTimeUnitString(result.time_unit);
130-
printer(Out, COLOR_YELLOW, "%10.0f %s %10.0f %s ", real_time, timeLabel,
131-
cpu_time, timeLabel);
148+
printer(Out, COLOR_YELLOW, "%s %-4s %s %-4s ", real_time_str.c_str(), timeLabel,
149+
cpu_time_str.c_str(), timeLabel);
132150
}
133151

134152
if (!result.report_big_o && !result.report_rms) {

test/complexity_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ int AddComplexityTest(std::string test_name, std::string big_o_test_name,
1717
SetSubstitutions({{"%name", test_name},
1818
{"%bigo_name", big_o_test_name},
1919
{"%rms_name", rms_test_name},
20-
{"%bigo_str", "[ ]* %float " + big_o},
20+
{"%xbigo_str", "[ ]*%float[ ]*" + big_o},
2121
{"%bigo", big_o},
2222
{"%rms", "[ ]*[0-9]+ %"}});
2323
AddCases(
2424
TC_ConsoleOut,
25-
{{"^%bigo_name %bigo_str %bigo_str[ ]*$"},
25+
{{"^%bigo_name %xbigo_str %xbigo_str[ ]*$"},
2626
{"^%bigo_name", MR_Not}, // Assert we we didn't only matched a name.
2727
{"^%rms_name %rms %rms[ ]*$", MR_Next}});
2828
AddCases(TC_JSONOut, {{"\"name\": \"%bigo_name\",$"},

test/output_test_helper.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ SubMap& GetSubstitutions() {
3838
// Don't use 'dec_re' from header because it may not yet be initialized.
3939
// clang-format off
4040
static std::string safe_dec_re = "[0-9]*[.]?[0-9]+([eE][-+][0-9]+)?";
41+
static std::string time_re = "([0-9]+[.])?[0-9]+";
4142
static SubMap map = {
4243
{"%float", "[0-9]*[.]?[0-9]+([eE][-+][0-9]+)?"},
4344
// human-readable float
4445
{"%hrfloat", "[0-9]*[.]?[0-9]+([eE][-+][0-9]+)?[kMGTPEZYmunpfazy]?"},
4546
{"%int", "[ ]*[0-9]+"},
4647
{" %s ", "[ ]+"},
47-
{"%time", "[ ]*[0-9]+ ns"},
48-
{"%console_report", "[ ]*[0-9]+ ns [ ]*[0-9]+ ns [ ]*[0-9]+"},
49-
{"%console_time_only_report", "[ ]*[0-9]+ ns [ ]*[0-9]+ ns"},
50-
{"%console_us_report", "[ ]*[0-9]+ us [ ]*[0-9]+ us [ ]*[0-9]+"},
51-
{"%console_us_time_only_report", "[ ]*[0-9]+ us [ ]*[0-9]+ us"},
48+
{"%time", "[ ]*" + time_re + "[ ]+ns"},
49+
{"%console_report", "[ ]*" + time_re + "[ ]+ns [ ]*" + time_re + "[ ]+ns [ ]*[0-9]+"},
50+
{"%console_time_only_report", "[ ]*" + time_re + "[ ]+ns [ ]*" + time_re + "[ ]+ns"},
51+
{"%console_us_report", "[ ]*" + time_re + "[ ]+us [ ]*" + time_re + "[ ]+us [ ]*[0-9]+"},
52+
{"%console_us_time_only_report", "[ ]*" + time_re + "[ ]+us [ ]*" + time_re + "[ ]+us"},
5253
{"%csv_header",
5354
"name,iterations,real_time,cpu_time,time_unit,bytes_per_second,"
5455
"items_per_second,label,error_occurred,error_message"},

test/reporter_output_test.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void BM_Complexity_O1(benchmark::State& state) {
229229
state.SetComplexityN(state.range(0));
230230
}
231231
BENCHMARK(BM_Complexity_O1)->Range(1, 1 << 18)->Complexity(benchmark::o1);
232-
SET_SUBSTITUTIONS({{"%bigOStr", "[ ]* %float \\([0-9]+\\)"},
232+
SET_SUBSTITUTIONS({{"%bigOStr", "[ ]* %float[ ]+\\([0-9]+\\)"},
233233
{"%RMS", "[ ]*[0-9]+ %"}});
234234
ADD_CASES(TC_ConsoleOut, {{"^BM_Complexity_O1_BigO %bigOStr %bigOStr[ ]*$"},
235235
{"^BM_Complexity_O1_RMS %RMS %RMS[ ]*$"}});
@@ -511,19 +511,19 @@ BENCHMARK(BM_UserStats)
511511
// check that user-provided stats is calculated, and is after the default-ones
512512
// empty string as name is intentional, it would sort before anything else
513513
ADD_CASES(TC_ConsoleOut, {{"^BM_UserStats/iterations:5/repeats:3/manual_time [ "
514-
"]* 150 ns %time [ ]*5$"},
514+
"]* 150[ ]+ns %time [ ]*5$"},
515515
{"^BM_UserStats/iterations:5/repeats:3/manual_time [ "
516-
"]* 150 ns %time [ ]*5$"},
516+
"]* 150[ ]+ns %time [ ]*5$"},
517517
{"^BM_UserStats/iterations:5/repeats:3/manual_time [ "
518-
"]* 150 ns %time [ ]*5$"},
518+
"]* 150[ ]+ns %time [ ]*5$"},
519519
{"^BM_UserStats/iterations:5/repeats:3/"
520-
"manual_time_mean [ ]* 150 ns %time [ ]*3$"},
520+
"manual_time_mean [ ]* 150[ ]+ns %time [ ]*3$"},
521521
{"^BM_UserStats/iterations:5/repeats:3/"
522-
"manual_time_median [ ]* 150 ns %time [ ]*3$"},
522+
"manual_time_median [ ]* 150[ ]+ns %time [ ]*3$"},
523523
{"^BM_UserStats/iterations:5/repeats:3/"
524-
"manual_time_stddev [ ]* 0 ns %time [ ]*3$"},
524+
"manual_time_stddev [ ]* 0.000[ ]+ns %time [ ]*3$"},
525525
{"^BM_UserStats/iterations:5/repeats:3/manual_time_ "
526-
"[ ]* 150 ns %time [ ]*3$"}});
526+
"[ ]* 150[ ]+ns %time [ ]*3$"}});
527527
ADD_CASES(
528528
TC_JSONOut,
529529
{{"\"name\": \"BM_UserStats/iterations:5/repeats:3/manual_time\",$"},

0 commit comments

Comments
 (0)
0