Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 3 additions & 40 deletions go-runner/overlay/benchmark1.24.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,45 +356,7 @@ func (b *B) launch() {
b.runN(b.benchTime.n)
}
} else {
warmupD := b.benchTime.d / 10
warmupN := int64(1)
for n := int64(1); !b.failed && b.duration < warmupD && n < 1e9; {
last := n
// Predict required iterations.
goalns := warmupD.Nanoseconds()
prevIters := int64(b.N)
n = int64(predictN(goalns, prevIters, b.duration.Nanoseconds(), last))
b.runN(int(n))
warmupN = n
}

// Reset the fields from the warmup run
b.ResetTimer()

// Final run:
benchD := b.benchTime.d
benchN := predictN(benchD.Nanoseconds(), int64(b.N), b.duration.Nanoseconds(), warmupN)

// When we have a very slow benchmark (e.g. taking 500ms), we have to:
// 1. Reduce the number of rounds to not slow down the process (e.g. by executing a 1s bench 100 times)
// 2. Not end up with roundN of 0 when dividing benchN (which can be < 100) by rounds
const minRounds = 100
var rounds int
var roundN int
if benchN < minRounds {
rounds = benchN
roundN = 1
} else {
rounds = minRounds
roundN = benchN / int(rounds)
}

b.codspeed.instrument_hooks.StartBenchmark()
for range rounds {
b.runN(int(roundN))
}
b.codspeed.instrument_hooks.StopBenchmark()
b.sendAccumulatedTimestamps()
runBenchmarkWithWarmup(b)
}
}
b.result = BenchmarkResult{b.N, b.duration, b.bytes, b.netAllocs, b.netBytes, b.codspeedTimePerRoundNs, b.codspeedItersPerRound, b.extra}
Expand Down Expand Up @@ -468,6 +430,7 @@ func (b *B) loopSlowPath() bool {
}
// Within a b.Loop loop, we don't use b.N (to avoid confusion).
b.N = 0
b.loopStartTime = time.Now()
b.codspeed.instrument_hooks.StartBenchmark()
b.ResetTimer()
b.StartTimerWithoutMarker()
Expand All @@ -489,7 +452,7 @@ func (b *B) loopSlowPath() bool {
more = false
} else {
// Handle fixed time case
more = b.stopOrScaleBLoop()
more = b.stopOrScaleBLoopCodspeed()
}
if !more {
// NOTE: We could move the endTimestamp capturing further up or even into the Loop() function
Expand Down
Loading
Loading