Skip to content

Add a new benchstat-like output format - #2402

Open
DenysZm wants to merge 1 commit into
google:mainfrom
DenysZm:benchstat_output
Open

DenysZm wants to merge 1 commit into
google:mainfrom
DenysZm:benchstat_output

Conversation

@DenysZm

@DenysZm DenysZm commented Nov 25, 2026

Copy link
Copy Markdown

This commit adds a new print option --format=benchstat
In contrast to a default side-by-side table,
this new mode instead prints one compact table per metric,
in the style of Go's benchstat.

This PR closes #2397

Assisted-By: Antigravity

This commit adds a new print option `--format=benchstat`
In a contrast to a default  side-by-side table,
this new mode instead prints one compact table per metric, in the
style of Go's [benchstat](https://pkg.go.dev/golang.org/x/perf/cmd/benchstat).

Assisted-By: Antigravity
@google-cla

google-cla Bot commented Nov 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@LebedevRI LebedevRI left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I can't tell what those tests are testing.
What is the actual behaviour if:

  • there are no repetitions in the input
  • there are only aggregates in the input
  • input contains repetitions and their aggregates

Comment thread tools/gbench/report.py
Comment on lines +1926 to +1946
def test_format_with_suffix(self):
self.assertEqual(format_with_suffix(None), "N/A")
self.assertEqual(format_with_suffix(0), "0.00")
self.assertEqual(format_with_suffix(12), "12.00")
self.assertEqual(format_with_suffix(999.9), "999.90")
self.assertEqual(format_with_suffix(1000), "1.00K")
self.assertEqual(format_with_suffix(8256525), "8.26M")
self.assertEqual(format_with_suffix(4868373980), "4.87G")
self.assertEqual(format_with_suffix(1234567890123), "1.23T")

def test_format_time_s(self):
self.assertEqual(format_time_s(None), "N/A")
self.assertEqual(format_time_s(0.0), "0.00ns")
self.assertEqual(format_time_s(4.25e-8), "42.50ns")
self.assertEqual(format_time_s(1.5e-4), "150.0us")
self.assertEqual(format_time_s(0.1147), "114.7ms")
self.assertEqual(format_time_s(3.071), "3.07s")
# Rounding up to a boundary moves on to the next unit / precision.
self.assertEqual(format_time_s(9.99996e-7), "1.00us")
self.assertEqual(format_time_s(0.99996), "1.00s")
self.assertEqual(format_time_s(9.9999e-5), "100.0us")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is the number of decimal digits enforced by benchstat format?
I think the existing formatting elsewhere in the repo is a mistake,
and we should consistently use engineering format,
i.e. deduce the suffix as usual, and then always print exactly 4 digits.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] New "benchstat" output format

2 participants