Skip to content

Commit 93f2c82

Browse files
committed
wip: prevent reusing startTimestamp
1 parent c979e15 commit 93f2c82

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

testing/testing/benchmark.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ func (b *B) StartTimer() {
164164
b.timerOn = true
165165
// b.loop.i &^= loopPoisonTimer
166166

167+
// Capture fresh start timestamp for this timing session
167168
b.codspeed.startTimestamp = capi.CurrentTimestamp()
168169
}
169170
}
@@ -182,14 +183,17 @@ func (b *B) StopTimer() {
182183
// If we hit B.Loop with the timer stopped, fail.
183184
// b.loop.i |= loopPoisonTimer
184185

186+
// Only accumulate timestamps if we have a valid start timestamp
187+
if b.codspeed.startTimestamp == 0 {
188+
panic(fmt.Sprintf("StopTimer called without StartTimer for benchmark %s", b.name))
189+
}
190+
185191
// Accumulate timestamps for batch submission instead of immediate hook call
186192
b.codspeed.accumulatedStartTimestamps = append(b.codspeed.accumulatedStartTimestamps, b.codspeed.startTimestamp)
187193
b.codspeed.accumulatedEndTimestamps = append(b.codspeed.accumulatedEndTimestamps, endTimestamp)
188194

189-
// Debug log every 10000 accumulated timestamps to detect potential memory issues
190-
if len(b.codspeed.accumulatedStartTimestamps)%10000 == 0 && len(b.codspeed.accumulatedStartTimestamps) > 0 {
191-
fmt.Printf("DEBUG: Accumulated %d timestamp pairs for benchmark %s\n", len(b.codspeed.accumulatedStartTimestamps), b.name)
192-
}
195+
// Reset startTimestamp to prevent reuse
196+
b.codspeed.startTimestamp = 0
193197

194198
// For b.N loops: This will be called in runN which sets b.N to the number of iterations.
195199
// For b.Loop() loops: loopSlowPath sets b.N to 0 to prevent b.N loops within b.Loop. However, since

0 commit comments

Comments
 (0)