]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.24] testing: separate b.Loop counter from b.N
authorAustin Clements <austin@google.com>
Wed, 19 Mar 2025 15:46:41 +0000 (11:46 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 26 Mar 2025 16:41:02 +0000 (09:41 -0700)
commit9204aca6c2a95277f2e3df4215c515ab38c008c8
treea357107f394ad20ac1f4ff3fccbff2f7fc8cee06
parent0ae3ca0a20db5f9df978fa59cd0e8751ac9f5250
[release-branch.go1.24] testing: separate b.Loop counter from b.N

Currently, b.Loop uses b.N as the iteration count target. However,
since it updates the target as it goes, the behavior is quite
different from a b.N-style benchmark. To avoid user confusion, this CL
gives b.Loop a separate, unexported iteration count target. It ensures
b.N is 0 within the b.Loop loop to help catch misuses, and commits the
final iteration count to b.N only once the loop is done (as the
documentation states "After Loop returns false, b.N contains the total
number of iterations that ran, so the benchmark may use b.N to compute
other average metrics.")

Since there are now two variables used by b.Loop, we put them in an
unnamed struct. Also, we rename b.loopN to b.loop.i because this
variable tracks the current iteration index (conventionally "i"), not
the target (conventionally "n").

Unfortunately, a simple renaming causes B.Loop to be too large for the
inliner. Thus, we make one simplification to B.Loop to keep it under
the threshold. We're about to lean into that simplification anyway in
a follow-up CL, so this is just temporary.

For #72974.

Change-Id: Ide1c4f1b9ca37f300f3beb0e60ba6202331b183e
Reviewed-on: https://go-review.googlesource.com/c/go/+/659655
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/660556
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
src/testing/benchmark.go
src/testing/loop_test.go