- 提升 go.mod 基线到 Go 1.20,并补齐对应测试 - 修正 Passwd / PasswdResponseSignal 语义,Ctrl+C 默认退出当前流程 - 优化 raw terminal redraw、Restore 与 StopUntil 的边界行为 - 新增 StarPipe、FrameReader/FrameWriter、ReadFullContext/WriteFullContext/CopyContext、IsTerminal/ReadPasswordContext - 收口 StarQueue / StarBuffer 语义,删除 EndWrite,统一 Close / Abort 行为 - 补齐 signal、timeout、queue、terminal、pipe、buffer 的回归测试与 race 覆盖
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
package stario
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func benchmarkRawRedrawAppend(b *testing.B, current []rune, next rune, mask string) {
|
|
b.Run("legacy", func(b *testing.B) {
|
|
ioBuf := make([]rune, len(current)+1)
|
|
copy(ioBuf, current)
|
|
ioBuf[len(current)] = next
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
echo := renderRawEcho(ioBuf, mask)
|
|
_ = stringDisplayWidth(echo)
|
|
}
|
|
})
|
|
|
|
b.Run("fast", func(b *testing.B) {
|
|
maskWidth := stringDisplayWidth(mask)
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, _, ok := rawEchoRenderUnit(next, mask, maskWidth)
|
|
if !ok {
|
|
b.Fatal("fast path rejected append rune")
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func benchmarkRawRedrawBackspace(b *testing.B, current []rune, mask string) {
|
|
if len(current) == 0 {
|
|
b.Fatal("backspace benchmark requires non-empty input")
|
|
}
|
|
last := current[len(current)-1]
|
|
trimmed := current[:len(current)-1]
|
|
|
|
b.Run("legacy", func(b *testing.B) {
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
echo := renderRawEcho(trimmed, mask)
|
|
_ = stringDisplayWidth(echo)
|
|
}
|
|
})
|
|
|
|
b.Run("fast", func(b *testing.B) {
|
|
maskWidth := stringDisplayWidth(mask)
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, _, ok := rawEchoRenderUnit(last, mask, maskWidth)
|
|
if !ok {
|
|
b.Fatal("fast path rejected backspace rune")
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func BenchmarkRawRedrawAppendPlainLong(b *testing.B) {
|
|
current := []rune(strings.Repeat("a", 4096))
|
|
benchmarkRawRedrawAppend(b, current, 'b', "")
|
|
}
|
|
|
|
func BenchmarkRawRedrawAppendMaskLong(b *testing.B) {
|
|
current := []rune(strings.Repeat("a", 4096))
|
|
benchmarkRawRedrawAppend(b, current, 'b', "[]")
|
|
}
|
|
|
|
func BenchmarkRawRedrawBackspacePlainLong(b *testing.B) {
|
|
current := []rune(strings.Repeat("a", 4096))
|
|
benchmarkRawRedrawBackspace(b, current, "")
|
|
}
|
|
|
|
func BenchmarkRawRedrawBackspaceMaskLong(b *testing.B) {
|
|
current := []rune(strings.Repeat("a", 4096))
|
|
benchmarkRawRedrawBackspace(b, current, "[]")
|
|
}
|