-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: testing: custom benchmark labels #28398
Comments
Dup of #26037? I’d love to see that go in for 1.12 but I don’t think either @aclements or I have the bandwidth to push it through. |
Oh, reading closer, not a dup. Sorry. At least I’ve now cc’d Austin. :) |
Seemed this should have the |
What exactly are you proposing? Adding an option to |
An option to ProposalMy concrete proposal is an additional function in the // SetBenchmarkLabel records a value relevant to benchmark performance. This
// will be included in benchmark output ahead of individual benchmark results.
// Labels "goos", "goarch" and "pkg" are set by default.
SetBenchmarkLabel(key, value string) Not sure about naming, but hopefully this gives the idea. "Case Study"I recently implmented Meow hash for Golang. This hash is designed to take advantage of hardware AES instructions, therefore the implementation dispatches to one of three backends based on CPUID flags at runtime (pure Go, AES-NI and VAES-256/512). To provide useful context in the test/benchmark output, I have two test functions that exist https://github.com/mmcloughlin/meow/blob/7358a9c1d22772fbddc8c47fd74cf501c0136ec1/dispatch_amd64_test.go#L10-L17 I would prefer to include these as "official" labels: testing.SetBenchmarkLabel("backend", implementation)
testing.SetBenchmarkLabel("hasaesni", cpu.HasAES)
testing.SetBenchmarkLabel("hasavx", cpu.HasAVX)
... Comparison: Google BenchmarkNote that Google benchmark also provides context with benchmark runs. For
It would be great it was also possible to add CPU/cache information in Go Benchmark FormatNote that this output has been formalized in the following document: In particular these "labels" are called "Configuration Lines". Moreover, this document makes |
Change https://golang.org/cl/146897 mentions this issue: |
Added a CL to concretely demonstrate the proposal (and get something on the record before the freeze). |
I'd use it if it existed, which I like to think is an argument in favor. |
Does SetBenchmarkLabel keep track of what's already been printed and not repeat prints? In theory you can change the labels between runs. |
The existing implementation (and prototype CL) print the labels inside a // SetBenchmarkLabel records a value relevant to benchmark performance. This
// will be included in benchmark output ahead of individual benchmark results.
// Any SetBenchmarkLabel calls after the first benchmark is executed will be
// ignored. Labels "goos", "goarch" and "pkg" are set by default.
SetBenchmarkLabel(key, value string) Did you have some other behavior in mind? |
SetBenchmarkLabel should track what it has printed (a map[string]string) and silence duplicate prints but not throw away prints that change the value associated with a given key. Otherwise this seems OK to me. @aclements? |
Ping @aclements |
Yes it would be great to get @aclements input.
This seems easy enough, but I'd like to understand the use case you have in mind. Are you thinking about |
Is this addressed by the recent fix for #26037? CC @aclements |
Nope, this is not a dup of #26037. That was my initial reaction as well though. :) See the beginning of the thread. This is about the labels that are printed prior to the benchmark lines, not the information that is included in the benchmark lines. |
Adding to the ping party for @aclements |
I'd like to understand what @rsc is proposing here a bit better, too. It does seem a bit odd that
|
I was thinking that this would be something done inside a Benchmark function, but Austin points out that at that point the "BenchmarkName " prefix has been printed, making it inconvenient to print new key:value pairs. Also, the examples in the initial request are all global to the process, so maybe it makes sense to scope down to something global to the process that gets printed before any benchmarks start. Then the only question is how do we know benchmarks are about to start. TestMain could print them unconditionally even today. If we give TestMain more access to the list of intended tests and benchmarks (see #28592) then it could avoid the print if no benchmarks will run. But maybe the lines in question would not be so bad to print always, so maybe we don't need to do anything special at all. For that matter, As far as the case study, that could be done today with:
|
Based on my comment from last week, I'm leaning toward declining this proposal. The answer to the original question is just "print statements". |
In my opinion there's value in making this a "first class citizen". Printing works but feels hacky. Here's a hypothetical (but I believe not far fetched) reason why this could matter down the line. Google Benchmark offers
Now my print statements give me:
I'm not arguing for this specific feature right now. My point is just that if people are printing labels, you've lost the semantics, and are unable to manipulate the labels in any structured way. Finally, I think adding this as a function encourages people to use it, which I think is a positive too. |
The JSON output is converted by a different program by parsing the actual benchmark output. Printing will not affect that. Let's let people do print statements for now and revisit once we can see more usage. |
Currently go benchmark output reports some labels:
These are added by
go/src/testing/benchmark.go
Lines 277 to 283 in dd78955
It would be great if the user could add custom labels relevant to the performance of their code. For example:
I have noticed that the
perf.golang.org
service appears to support this, but I haven't looked into exactly how. Apologies if I've overlooked some existing feature.The text was updated successfully, but these errors were encountered: