mirror of
https://github.com/peco/peco.git
synced 2026-09-10 07:16:29 -04:00
Benchmark (10k lines): plain text: 1023us -> 37us (-96%), 1.7MiB -> 0B (-100%), 30k -> 0 allocs 95% plain: 1064us -> 162us (-85%), 1720KiB -> 63KiB (-96%), 30.5k -> 2k allocs
41 lines
898 B
Go
41 lines
898 B
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkStripANSISequenceBulk(b *testing.B) {
|
|
b.Run("10k_plain_lines", func(b *testing.B) {
|
|
lines := make([]string, 10_000)
|
|
for i := range lines {
|
|
lines[i] = fmt.Sprintf("line %d: this is a typical line without any ansi codes at all padding", i)
|
|
}
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for b.Loop() {
|
|
for _, l := range lines {
|
|
StripANSISequence(l)
|
|
}
|
|
}
|
|
})
|
|
|
|
b.Run("10k_mixed_95pct_plain", func(b *testing.B) {
|
|
lines := make([]string, 10_000)
|
|
for i := range lines {
|
|
if i%20 == 0 {
|
|
lines[i] = fmt.Sprintf("\x1b[31mline %d\x1b[0m: this has ansi codes in it for color", i)
|
|
} else {
|
|
lines[i] = fmt.Sprintf("line %d: this is a typical line without any ansi codes at all padding", i)
|
|
}
|
|
}
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for b.Loop() {
|
|
for _, l := range lines {
|
|
StripANSISequence(l)
|
|
}
|
|
}
|
|
})
|
|
}
|