Files
sower/router/ruleset_bench_test.go
wweir defea58ac2 perf: batch byte accounting and bound gateway memory
- countingConn batches per-domain attribution (32KiB/500ms) so the relay
  hot path pays two atomics per I/O instead of a global mutex; Close drains
- Precompute OTel byte attributes to drop per-I/O allocations
- suffixtree: indexMap only for nodes with >=8 children; Match stays
  read-only for concurrent queries
- Soft Go memory limit (128MiB default, GOMEMLIMIT/SOWER_MEMORY_LIMIT_MB
  override) cuts resident memory from ~240MB to ~130MB on the default
  ad/china/gfw rule sets
- Split stats.go into snapshot/eviction/counting by responsibility
2026-08-07 12:02:26 +08:00

35 lines
631 B
Go

package router
import (
"fmt"
"testing"
)
func BenchmarkRuleSetMatch(b *testing.B) {
rules := make([]string, 0, 10000)
for i := 0; i < 10000; i++ {
rules = append(rules, fmt.Sprintf("host%d.example.com", i))
}
rs := NewRuleSet(rules...)
b.ReportAllocs()
b.ResetTimer()
for range b.N {
rs.Match("www.example.com")
}
}
func BenchmarkRuleSetMatchHit(b *testing.B) {
rules := make([]string, 0, 10000)
for i := 0; i < 10000; i++ {
rules = append(rules, fmt.Sprintf("host%d.example.com", i))
}
rs := NewRuleSet(rules...)
b.ReportAllocs()
b.ResetTimer()
for range b.N {
rs.Match("host5000.example.com")
}
}