-
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
testing: add an example showcasing B.RunParallel with B.ReportMetric #50756
Comments
It might also be a good idea for RunParallel to call out that using |
Change https://go.dev/cl/415035 mentions this issue: |
…mark. Show how to use b.N within a parallel benchmark at the setup and reporting phases of the benchmark. Indicate that atomic operations must be used within the benchmark for loop and that b.N can reliably be derefenced from outside of the benchmark for loop. Fixes golang#50756
…mark Show how to use b.N within a parallel benchmark at the setup and reporting phases of the benchmark. Indicate that atomic operations must be used within the benchmark for loop and that b.N can reliably be derefenced from outside of the benchmark for loop. Fixes golang#50756
Change https://go.dev/cl/437815 mentions this issue: |
This commit was dedicated to adding an example of using B.ReportMetrics with B.RunParallel called ExampleB_ReportMetric_parallel. In this example, the same algorithm for ExampleB_ReportMetric was used, instead with a concurrent for loop using PB.Next instead of a standard one. There is also notes noting when to use the B.ReportMetric methods when running concurrent testing. Fixes golang#50756 Change-Id: I2a621b4e367af5f4ec47d38a0da1035a8d52f628 Reviewed-on: https://go-review.googlesource.com/c/go/+/437815 Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
I had a parallel benchmark in the form of:
I was taking a second look at the benchmark because dividing by
b.N
seemed fishy. This is a parallel benchmark, where I iterate viapb.Next
and notb.N
, so can I rely onb.N
being an accurate detail of how many iterations were run across all goroutines?The docs seem to imply so:
Still, I had to re-read the docs multiple times to convince myself. I think it would be nice to add an example on ReportMetric for parallel benchmarks, such as
func ExampleB_ReportMetric_parallel
, to help clarify the interaction between the two and how they are meant to be used.And there's another reason why an example would be good: since
RunParallel
hides the goroutine spawning from the user, it's relatively easy to introduce data races by mistake, like I did above!totalFoo += someFoo()
would need to be something likeatomic.AddInt64(&totalFoo, someFoo())
. The example could also show that.Marking as a good candidate for first time contributors. Happy to review it too.
cc @mpvl per https://dev.golang.org/owners
The text was updated successfully, but these errors were encountered: