Gim/internal/syntax/treesitter_bench_test.go
Hayden Hargreaves be13f8838d
All checks were successful
Run Test Suite / test (push) Successful in 31s
fix: remove the styles package, fixed tests
However, the colorscheme functions and tests do not work anymore, they
need to be rebuilt.
2026-04-07 22:43:00 -07:00

38 lines
977 B
Go

package syntax
import (
"fmt"
"testing"
"git.gophernest.net/azpect/TextEditor/internal/core"
"git.gophernest.net/azpect/TextEditor/internal/theme/themes"
)
func BenchmarkTreeSitterPrepareAndIncrementalEdit(b *testing.B) {
lines := make([]string, 0, 2000)
lines = append(lines, "package main", "", "func main() {")
for i := 0; i < 1990; i++ {
lines = append(lines, fmt.Sprintf(" v%d := %d", i, i))
}
lines = append(lines, "}")
bld := core.NewBufferBuilder().WithFilename("bench.go").WithFiletype("go").WithLines(lines).Build()
buf := &bld
eng := NewTreeSitterEngine(themes.NewDefaultTheme())
eng.PrepareBuffer(buf)
b.ResetTimer()
for i := 0; i < b.N; i++ {
lineIdx := 10 + (i % 1000)
buf.SetLine(lineIdx, fmt.Sprintf(" v%d := %d", lineIdx, i))
oldSource := buildBufferSource(buf)
_ = oldSource
// Synthetic direct invalidate path benchmark (current API entrypoints)
eng.InvalidateLines(buf, lineIdx, lineIdx)
eng.PrepareBuffer(buf)
}
}