Repository navigation
testing: b.StopTimer breaks b.Loop #72922
Copy link
Copy link
Closed
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.Issues that have a fix which has not yet been reviewed or submitted.FrozenDueToAge
Milestone
Description
Activity
CC @JunyangShao
Reacted by Junyang ShaoRelated Issues
- testing: tiny benchmark with StopTimer runs forever #27217
- testing: benchmark ignores time spent while timer is stopped when choosing N #23998 (closed)
- testing: add testing.B.Loop for iteration #61515 (closed)
- cmd/go: -test.timeout=0 does not cancel go tool's test timeout #18490 (closed)
- time: timer reset sometimes ignored, causing delayed ticks #47762 (closed)
- go/benchmark only takes timer measurement as parameter to increase b.N #40226 (closed)
Related Code Changes
Related Documentation
Related Discussions
- Bencharking issue with b.StartTimer and b.StopTimer. Was: Benchmark using b.StopTimer and b.StartTimer has unexpected behaviour - to me at least
- benchmark and start/stop timer
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
- addedBugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.
on Mar 18, 2025 Change https://go.dev/cl/658975 mentions this issue:
testing: allow manual timer control in testing.B.Loop@gopherbot, please backport to Go 1.24.
Backport issue(s) opened: #72934 (for 1.24).
Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.
- addedFixPendingIssues that have a fix which has not yet been reviewed or submitted.Issues that have a fix which has not yet been reviewed or submitted.
on Mar 19, 2025 - added a commit that references this issue
on Mar 20, 2025 - locked and limited conversation to collaborators
on Mar 20, 2026
Metadata
Metadata
Assignees
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.Issues that have a fix which has not yet been reviewed or submitted.FrozenDueToAge
Go version
go version go1.24.1 linux/amd64
Output of
go envin your module/workspace:What did you do?
Consider the following benchmark function:
Run with
go test -bench=. -benchtime=1sb.Loopnever returns false and the benchmark never terminates.In
B.stopOrScaleBLoopwe useb.startto compute how long we took to iterateb.Ntimes. However, callingB.StartTimersetsb.startto the current time.None of the documentation says that using
b.StopTimer/b.StartTimeris forbidden when usingb.Loop.