mirror of
https://github.com/peco/peco.git
synced 2026-09-10 07:16:29 -04:00
CI's golangci-lint modernize check flags `for range b.N`; switch to `b.Loop()`, which also handles timer reset internally.
30 lines
761 B
Go
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)
|
|
}
|
|
}
|