@@ -164,6 +164,7 @@ func (b *B) StartTimer() {
164
164
b .timerOn = true
165
165
// b.loop.i &^= loopPoisonTimer
166
166
167
+ // Capture fresh start timestamp for this timing session
167
168
b .codspeed .startTimestamp = capi .CurrentTimestamp ()
168
169
}
169
170
}
@@ -182,14 +183,17 @@ func (b *B) StopTimer() {
182
183
// If we hit B.Loop with the timer stopped, fail.
183
184
// b.loop.i |= loopPoisonTimer
184
185
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
+
185
191
// Accumulate timestamps for batch submission instead of immediate hook call
186
192
b .codspeed .accumulatedStartTimestamps = append (b .codspeed .accumulatedStartTimestamps , b .codspeed .startTimestamp )
187
193
b .codspeed .accumulatedEndTimestamps = append (b .codspeed .accumulatedEndTimestamps , endTimestamp )
188
194
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
193
197
194
198
// For b.N loops: This will be called in runN which sets b.N to the number of iterations.
195
199
// For b.Loop() loops: loopSlowPath sets b.N to 0 to prevent b.N loops within b.Loop. However, since
0 commit comments