Gim/internal/syntax/treesitter_bench_test.go
Hayden Hargreaves 16d1318c22 feat: start TS impl
This is so vibe coded, but in the interest of time, its a bit
necessary. Plus this is a complex problem that I don't have the mental
bandwidth to invest right now.
2026-04-07 10:23:25 -07:00

38 lines
967 B
Go

package syntax
import (
"fmt"
"testing"
"git.gophernest.net/azpect/TextEditor/internal/core"
"git.gophernest.net/azpect/TextEditor/internal/style"
)
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(style.DefaultStyles())
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)
}
}