Skip to content

Conversation

biojppm
Copy link
Contributor

@biojppm biojppm commented Mar 2, 2017

This PR adds the option --benchmark_counters_tabular={true|false}, which makes the ConsoleReporter print the user counters in tabular format. The option defaults to false. This follows discussions in PR #262 (notably this and this).

To be clear:

  • by default, counters are printed at the end, the same way as bytes_processed and items_processed, as agreed in Add user-defined counters. #262 . This is best for cases in which there are few counters, or where there are only a couple of lines per benchmark.
  • when --benchmark_counters_tabular=true is given, then the counters are printed as a column of the table. This is best for cases in which there are a lot of counters, or a lot of lines per benchmark.

Here's an example comparison between the two versions (Note that I removed some whitespace from both examples).

First the default --benchmark_counters_tabular=false:

------------------------------------------------------------------------------
Benchmark                        Time           CPU Iterations UserCounters...
------------------------------------------------------------------------------
BM_UserCounter/threads:8      2248 ns      10277 ns      68808 Bar=16 Bat=40 Baz=24 Foo=8
BM_UserCounter/threads:1      9797 ns       9788 ns      71523 Bar=2 Bat=5 Baz=3 Foo=1024m
BM_UserCounter/threads:2      4924 ns       9842 ns      71036 Bar=4 Bat=10 Baz=6 Foo=2
BM_UserCounter/threads:4      2589 ns      10284 ns      68012 Bar=8 Bat=20 Baz=12 Foo=4
BM_UserCounter/threads:8      2212 ns      10287 ns      68040 Bar=16 Bat=40 Baz=24 Foo=8
BM_UserCounter/threads:16     1782 ns      10278 ns      68144 Bar=32 Bat=80 Baz=48 Foo=16
BM_UserCounter/threads:32     1291 ns      10296 ns      68256 Bar=64 Bat=160 Baz=96 Foo=32
BM_UserCounter/threads:4      2615 ns      10307 ns      68040 Bar=8 Bat=20 Baz=12 Foo=4
BM_Factorial                    26 ns         26 ns   26608979 40320
BM_Factorial/real_time          26 ns         26 ns   26587936 40320
BM_CalculatePiRange/1           16 ns         16 ns   45704255 0
BM_CalculatePiRange/8           73 ns         73 ns    9520927 3.28374
BM_CalculatePiRange/64         609 ns        609 ns    1140647 3.15746
BM_CalculatePiRange/512       4900 ns       4901 ns     142696 3.14355

... compared to the tabular version --benchmark_counters_tabular=true. Note the additional printing of the header. This will happen any time the counter set changes.

---------------------------------------------------------------------------------------
Benchmark                        Time           CPU Iterations    Bar   Bat   Baz   Foo
---------------------------------------------------------------------------------------
BM_UserCounter/threads:8      2198 ns       9953 ns      70688     16    40    24     8
BM_UserCounter/threads:1      9504 ns       9504 ns      73787      2     5     3     1
BM_UserCounter/threads:2      4775 ns       9550 ns      72606      4    10     6     2
BM_UserCounter/threads:4      2508 ns       9951 ns      70332      8    20    12     4
BM_UserCounter/threads:8      2055 ns       9933 ns      70344     16    40    24     8
BM_UserCounter/threads:16     1610 ns       9946 ns      70720     32    80    48    16
BM_UserCounter/threads:32     1192 ns       9948 ns      70496     64   160    96    32
BM_UserCounter/threads:4      2506 ns       9949 ns      70332      8    20    12     4
--------------------------------------------------------------
Benchmark                        Time           CPU Iterations
--------------------------------------------------------------
BM_Factorial                    26 ns         26 ns   26392245 40320
BM_Factorial/real_time          26 ns         26 ns   26494107 40320
BM_CalculatePiRange/1           15 ns         15 ns   45571597 0
BM_CalculatePiRange/8           74 ns         74 ns    9450212 3.28374
BM_CalculatePiRange/64         595 ns        595 ns    1173901 3.15746
BM_CalculatePiRange/512       4752 ns       4752 ns     147380 3.14355
BM_CalculatePiRange/4k       37970 ns      37972 ns      18453 3.14184
BM_CalculatePiRange/32k     303733 ns     303744 ns       2305 3.14162
BM_CalculatePiRange/256k   2434095 ns    2434186 ns        288 3.1416
BM_CalculatePiRange/1024k  9721140 ns    9721413 ns         71 3.14159
BM_CalculatePi/threads:8      2255 ns       9943 ns      70936

@AppVeyorBot
Copy link

Build benchmark 540 failed (commit e0e3889b33 by @biojppm)

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 0de985a on biojppm:compact into ** on google:master**.

src/benchmark.cc Outdated
output_opts &= ~ConsoleReporter::OO_Tabular;
}
default_console_reporter = internal::CreateReporter(
FLAGS_benchmark_format, (ConsoleReporter::OutputOptions)output_opts);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use c++-style casts please.

prev_counters_.clear();

PrintBasicContext(&GetErrorStream(), context);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to update the WINDOWS build too. color_output_ is referenced in there.

@AppVeyorBot
Copy link

Build benchmark 541 failed (commit 4ec49b8a30 by @biojppm)

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling c846eed on biojppm:compact into ** on google:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling d84d911 on biojppm:compact into ** on google:master**.

@AppVeyorBot
Copy link

Build benchmark 542 failed (commit 10bc6154fe by @biojppm)

@dmah42
Copy link
Member

dmah42 commented Mar 2, 2017

Looks like one of the tests is failing for MinGW relating to console output. Could you take a look?

@biojppm
Copy link
Contributor Author

biojppm commented Apr 1, 2017

@dominichamon Sorry for the late reply. I did see that MinGW fail when I first pushed; I thought it was a spurious fail which I've sometimes seen with the output test.

Looking more closely, it is indeed something in the output test, and AFAICT it is unrelated to any counter logic; here's the message:

C:\projects\benchmark\test\output_test_helper.cc:93: CheckCase: Check `remaining_output.eof() == false' failed. End of output reached before match for regex "^BM_Repeat/repeats:3 %console_report$" was found
    actual regex string "^BM_Repeat/repeats:3 [ ]*[0-9]{1,5} ns [ ]*[0-9]{1,5} ns [ ]*[0-9]+$"
    started matching near: BM_Repeat/repeats:3                            4 ns         -0 ns    1000000
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information```

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 707dd89 on biojppm:compact into ** on google:master**.

@AppVeyorBot
Copy link

Build benchmark 570 completed (commit 3ce9f21d60 by @biojppm)

@biojppm
Copy link
Contributor Author

biojppm commented Apr 1, 2017

@dominichamon Indeed, the (same) PR is now passing Appveyor's MinGW test.

if(!run.counters.empty()) {
if(output_options_ & OO_Tabular) {
for(auto const& c : run.counters) {
str += FormatString(" %10s", c.first);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c.first.c_str() i think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! :-P

@AppVeyorBot
Copy link

Build benchmark 616 failed (commit d5091285f8 by @biojppm)

@coveralls
Copy link

Coverage Status

Coverage increased (+1.0%) to 86.486% when pulling 020bac9 on biojppm:compact into da8cd74 on google:master.


namespace {

bool IsZero(double n) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused function, apparently? in travis (clang release)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed by pragma-ignoring it, is it OK?

if(it == run.counters.end()) {
Out << ",";
}
else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this dropped 'else' isn't google style. can you run this change through clang-format with Google style selected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.0%) to 86.486% when pulling a310886 on biojppm:compact into da8cd74 on google:master.

@AppVeyorBot
Copy link

Build benchmark 617 failed (commit b0458113f2 by @biojppm)

@coveralls
Copy link

Coverage Status

Coverage increased (+1.0%) to 86.486% when pulling 1735413 on biojppm:compact into da8cd74 on google:master.

@biojppm
Copy link
Contributor Author

biojppm commented May 2, 2017

@dominichamon The previous push happened by accident. This push (or more precisely this push sequence) now completes the PR with unit tests. There may be some details which are so-so (the pragma ignore for -Wunused-function comes to mind, or the // clang format off), but other than that I think that's it.

@AppVeyorBot
Copy link

Build benchmark 618 failed (commit 09866a07f8 by @biojppm)

This thing with the pragma ignore was getting out of hand: now
MinGW (and probably GCC) was erroring too. So I chose to move
the definition of IsZero() out of the anonymous namespace into
benchmark.cc.
@biojppm
Copy link
Contributor Author

biojppm commented May 2, 2017

Hmmm. This thing with the pragma ignore is getting out of hand: now MinGW is complaining. I took the liberty of moving the definition of IsZero() out of the anonymous namespace into benchmark.cc.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.0%) to 86.486% when pulling ec6f035 on biojppm:compact into da8cd74 on google:master.

@AppVeyorBot
Copy link

Build benchmark 619 completed (commit 02184fedf1 by @biojppm)

@AppVeyorBot
Copy link

Build benchmark 620 completed (commit 03d2027393 by @biojppm)

@dmah42 dmah42 merged commit ec6f035 into google:master May 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants