search_bench_test.go

 1package backend
 2
 3import "testing"
 4
 5func BenchmarkParseSearchQuery_Simple(b *testing.B) {
 6	const q = "invoice"
 7	b.ReportAllocs()
 8	for i := 0; i < b.N; i++ {
 9		_ = ParseSearchQuery(q)
10	}
11}
12
13func BenchmarkParseSearchQuery_Complex(b *testing.B) {
14	const q = `from:alice@example.com to:bob@example.com subject:"Q4 invoice" body:overdue since:2026-01-01 before:2026-05-01 larger:1024 misc terms`
15	b.ReportAllocs()
16	for i := 0; i < b.N; i++ {
17		_ = ParseSearchQuery(q)
18	}
19}
20
21func BenchmarkTokenizeSearchQuery(b *testing.B) {
22	const q = `from:alice "long quoted phrase here" subject:foo body:bar`
23	b.ReportAllocs()
24	for i := 0; i < b.N; i++ {
25		_ = tokenizeSearchQuery(q)
26	}
27}