Now we can load them in via JSON files at launch time. They are embded in the final exe though...
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
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
|
|
editorTheme := themes.NewDefaultTheme()
|
|
eng := NewTreeSitterEngine(editorTheme)
|
|
|
|
eng.PrepareBuffer(buf, editorTheme)
|
|
|
|
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, editorTheme)
|
|
}
|
|
}
|