}
func (b *B) stopOrScaleBLoop() bool {
- timeElapsed := highPrecisionTimeSince(b.start)
- if timeElapsed >= b.benchTime.d {
+ t := b.Elapsed()
+ if t >= b.benchTime.d {
// Stop the timer so we don't count cleanup time
b.StopTimer()
return false
// Loop scaling
goalns := b.benchTime.d.Nanoseconds()
prevIters := int64(b.N)
- b.N = predictN(goalns, prevIters, timeElapsed.Nanoseconds(), prevIters)
+ b.N = predictN(goalns, prevIters, t.Nanoseconds(), prevIters)
b.loopN++
return true
}
func TestBenchmarkBLoop(t *T) {
var initialStart highPrecisionTime
var firstStart highPrecisionTime
- var lastStart highPrecisionTime
+ var scaledStart highPrecisionTime
var runningEnd bool
runs := 0
iters := 0
if iters == 0 {
firstStart = b.start
}
- lastStart = b.start
+ if iters == 1 {
+ scaledStart = b.start
+ }
iters++
}
finalBN = b.N
if firstStart == initialStart {
t.Errorf("b.Loop did not reset the timer")
}
- if lastStart != firstStart {
- t.Errorf("timer was reset during iteration")
+ if scaledStart != firstStart {
+ t.Errorf("b.Loop stops and restarts the timer during iteration")
}
// Verify that it stopped the timer after the last loop.
if runningEnd {