Skip to content

Commit 52c9bba

Browse files
committed
wip: add debug logs; remove start/stop timer in fast path of b.Loop()
1 parent b8d26b9 commit 52c9bba

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

testing/testing/benchmark.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,15 @@ func (b *B) StopTimer() {
182182
// If we hit B.Loop with the timer stopped, fail.
183183
// b.loop.i |= loopPoisonTimer
184184

185-
186185
// Accumulate timestamps for batch submission instead of immediate hook call
187186
b.codspeed.accumulatedStartTimestamps = append(b.codspeed.accumulatedStartTimestamps, b.codspeed.startTimestamp)
188187
b.codspeed.accumulatedEndTimestamps = append(b.codspeed.accumulatedEndTimestamps, endTimestamp)
189188

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+
}
193+
190194
// For b.N loops: This will be called in runN which sets b.N to the number of iterations.
191195
// For b.Loop() loops: loopSlowPath sets b.N to 0 to prevent b.N loops within b.Loop. However, since
192196
// we're starting/stopping the timer for each iteration in the b.Loop() loop, we can use 1 as
@@ -225,7 +229,11 @@ func (b *B) ResetTimer() {
225229
}
226230

227231
func (b *B) submitAccumulatedTimestamps() {
228-
for i := 0; i < len(b.codspeed.accumulatedStartTimestamps); i++ {
232+
numTimestamps := len(b.codspeed.accumulatedStartTimestamps)
233+
if numTimestamps > 0 {
234+
fmt.Printf("DEBUG: Submitting %d accumulated timestamp pairs for benchmark %s\n", numTimestamps, b.name)
235+
}
236+
for i := 0; i < numTimestamps; i++ {
229237
b.codspeed.instrument_hooks.AddBenchmarkTimestamps(
230238
b.codspeed.accumulatedStartTimestamps[i],
231239
b.codspeed.accumulatedEndTimestamps[i],
@@ -598,7 +606,7 @@ func (b *B) loopSlowPath() bool {
598606
// whereas b.N-based benchmarks must run the benchmark function (and any
599607
// associated setup and cleanup) several times.
600608
func (b *B) Loop() bool {
601-
b.StopTimer()
609+
// b.StopTimer()
602610
// This is written such that the fast path is as fast as possible and can be
603611
// inlined.
604612
//
@@ -613,7 +621,7 @@ func (b *B) Loop() bool {
613621
// path can do consistency checks and fail.
614622
if b.loop.i < b.loop.n {
615623
b.loop.i++
616-
b.StartTimer()
624+
// b.StartTimer()
617625
return true
618626
}
619627
return b.loopSlowPath()

0 commit comments

Comments
 (0)