peco.peco/source_capacity_bench_test.go
Daisuke Maki 643ad7881d modernize benchmark loop to b.Loop()
CI's golangci-lint modernize check flags `for range b.N`; switch to
`b.Loop()`, which also handles timer reset internally.
2026-06-04 11:13:46 +09:00

30 lines
761 B
Go

package peco
import (
"strconv"
"strings"
"testing"
"github.com/peco/peco/line"
)
// BenchmarkSourceAppendSaturated measures Append cost on a capacity-bounded
// source that is already saturated, which is the steady state for a long-lived
// streaming input (e.g. `tail -f | peco -b N`).
func BenchmarkSourceAppendSaturated(b *testing.B) {
const capacity = 10000
ig := newIDGen()
go ig.Run(b.Context())
s := NewSource("-", strings.NewReader(""), false, ig, capacity, false, false)
// Pre-fill to capacity so every benchmarked Append discards an old line.
for i := range capacity {
s.Append(line.NewRaw(uint64(i), strconv.Itoa(i), false, false))
}
l := line.NewRaw(uint64(capacity), "payload", false, false)
for b.Loop() {
s.Append(l)
}
}