benchmark_test.go 959 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }
  30. func BenchmarkCachedMarchGroup(b *testing.B) {
  31. g := NewMatcherGroup()
  32. for i := 1; i <= 1024; i++ {
  33. m, err := Domain.New(strconv.Itoa(i) + ".v2ray.com")
  34. common.Must(err)
  35. g.Add(m)
  36. }
  37. cg := NewCachedMatcherGroup(g)
  38. _ = cg.Match("0.v2ray.com")
  39. b.ResetTimer()
  40. for i := 0; i < b.N; i++ {
  41. _ = cg.Match("0.v2ray.com")
  42. }
  43. }