-
-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy pathlexer_benchmark_test.go
More file actions
56 lines (51 loc) · 1.31 KB
/
lexer_benchmark_test.go
File metadata and controls
56 lines (51 loc) · 1.31 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
package pongo2
import (
"testing"
)
// BenchmarkLexer measures lexer tokenization performance
func BenchmarkLexer(b *testing.B) {
testCases := []struct {
name string
input string
}{
{"keyword_in", "{% for x in items %}{{ x }}{% endfor %}"},
{"keyword_and_or", "{% if a and b or c %}yes{% endif %}"},
{"no_keywords", "{{ variable.field.subfield }}"},
{"mixed", "{% if item in items and active %}{{ item|escape }}{% endif %}"},
{"many_identifiers", "{{ a.b.c.d.e.f.g.h.i.j }}"},
}
for _, tc := range testCases {
b.Run(tc.name, func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := lex("benchmark", tc.input)
if err != nil {
b.Fatal(err)
}
}
})
}
}
// BenchmarkLexerStrings measures string escape handling performance
func BenchmarkLexerStrings(b *testing.B) {
testCases := []struct {
name string
input string
}{
{"simple_string", `{{ "hello world" }}`},
{"escaped_string", `{{ "hello \"world\" with \\backslash" }}`},
{"newline_string", `{{ "line1\nline2\ttab" }}`},
{"multiple_strings", `{{ "one" }}{{ "two" }}{{ "three" }}`},
}
for _, tc := range testCases {
b.Run(tc.name, func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := lex("benchmark", tc.input)
if err != nil {
b.Fatal(err)
}
}
})
}
}