benchmark_test.go 865 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 BenchmarkFullMatcherGroup(b *testing.B) {
  19. g := new(FullMatcherGroup)
  20. for i := 1; i <= 1024; i++ {
  21. g.Add(strconv.Itoa(i)+".v2ray.com", uint32(i))
  22. }
  23. b.ResetTimer()
  24. for i := 0; i < b.N; i++ {
  25. _ = g.Match("0.v2ray.com")
  26. }
  27. }
  28. func BenchmarkMarchGroup(b *testing.B) {
  29. g := new(MatcherGroup)
  30. for i := 1; i <= 1024; i++ {
  31. m, err := Domain.New(strconv.Itoa(i) + ".v2ray.com")
  32. common.Must(err)
  33. g.Add(m)
  34. }
  35. b.ResetTimer()
  36. for i := 0; i < b.N; i++ {
  37. _ = g.Match("0.v2ray.com")
  38. }
  39. }