-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_test.go
More file actions
69 lines (63 loc) · 1.42 KB
/
bench_test.go
File metadata and controls
69 lines (63 loc) · 1.42 KB
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
package cssx
import "testing"
var benchInputs = []struct {
name string
input string
}{
{"plain_selector", ".section .item"},
{"single_pseudo", ":count(.product)"},
{"nested", ":text(:first(h1))"},
{"attr_nested", ":attr(\"href\", :first(a.cta))"},
{"comma_in_attr", ":first(a[href*=\"x,y\"])"},
{"mixed", ":text(:nth(2, .section .item))"},
{"pipeline_sugar", ".section .item >> :nth(2) >> :text()"},
}
func BenchmarkParse(b *testing.B) {
b.ReportAllocs()
for _, tc := range benchInputs {
b.Run(tc.name, func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := Parse(tc.input); err != nil {
b.Fatal(err)
}
}
})
}
}
func BenchmarkBuildPipeline(b *testing.B) {
b.ReportAllocs()
asts := make([]AST, len(benchInputs))
for i, tc := range benchInputs {
ast, err := Parse(tc.input)
if err != nil {
b.Fatalf("parse failed for %q: %v", tc.input, err)
}
asts[i] = ast
}
b.ResetTimer()
for i, tc := range benchInputs {
ast := asts[i]
b.Run(tc.name, func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := BuildPipeline(ast); err != nil {
b.Fatal(err)
}
}
})
}
}
func BenchmarkCompile(b *testing.B) {
b.ReportAllocs()
for _, tc := range benchInputs {
b.Run(tc.name, func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := Compile(tc.input); err != nil {
b.Fatal(err)
}
}
})
}
}