-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbindings_bench_test.go
88 lines (73 loc) · 1.58 KB
/
bindings_bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package sitter_test
import (
"testing"
sitter "github.com/kiteco/go-tree-sitter"
"github.com/kiteco/go-tree-sitter/javascript"
)
var (
ResultUint32 uint32
ResultSymbol sitter.Symbol
ResultPoint sitter.Point
ResultString string
ResultNode *sitter.Node
)
func BenchmarkNode(b *testing.B) {
src := []byte("let a = 1")
p := sitter.NewParser()
defer p.Close()
p.SetLanguage(javascript.GetLanguage())
tree := p.Parse(src)
defer tree.Close()
root := tree.RootNode()
first := root.Child(0)
b.Run("Symbol", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ResultSymbol = first.Symbol()
}
})
b.Run("StartByte", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ResultUint32 = first.StartByte()
}
})
b.Run("EndByte", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ResultUint32 = first.EndByte()
}
})
b.Run("StartPoint", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ResultPoint = first.StartPoint()
}
})
b.Run("EndPoint", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ResultPoint = first.EndPoint()
}
})
b.Run("ChildCount", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ResultUint32 = first.ChildCount()
}
})
b.Run("Content", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ResultString = first.Content(src)
}
})
b.Run("Type", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ResultString = first.Type()
}
})
b.Run("Parent", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ResultNode = first.Parent()
}
})
b.Run("Child", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ResultNode = first.Child(0)
}
})
}