benchmark_test.go 627 B

123456789101112131415161718192021222324252627282930313233343536
  1. package strmatcher_test
  2. import (
  3. "strconv"
  4. "testing"
  5. "v2ray.com/core/common"
  6. . "v2ray.com/core/common/strmatcher"
  7. )
  8. func BenchmarkDomainMatcherGroup(b *testing.B) {
  9. g := new(DomainMatcherGroup)
  10. for i := 1; i <= 1024; i++ {
  11. g.Add(strconv.Itoa(i)+".v2ray.com", uint32(i))
  12. }
  13. b.ResetTimer()
  14. for i := 0; i < b.N; i++ {
  15. _ = g.Match("0.v2ray.com")
  16. }
  17. }
  18. func BenchmarkMarchGroup(b *testing.B) {
  19. g := NewMatcherGroup()
  20. for i := 1; i <= 1024; i++ {
  21. m, err := Domain.New(strconv.Itoa(i) + ".v2ray.com")
  22. common.Must(err)
  23. g.Add(m)
  24. }
  25. b.ResetTimer()
  26. for i := 0; i < b.N; i++ {
  27. _ = g.Match("0.v2ray.com")
  28. }
  29. }