benchmark_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package strmatcher_test
  2. import (
  3. "strconv"
  4. "testing"
  5. "github.com/xtls/xray-core/common"
  6. . "github.com/xtls/xray-core/common/strmatcher"
  7. )
  8. func BenchmarkACAutomaton(b *testing.B) {
  9. ac := NewACAutomaton()
  10. for i := 1; i <= 1024; i++ {
  11. ac.Add(strconv.Itoa(i)+".xray.com", Domain)
  12. }
  13. ac.Build()
  14. b.ResetTimer()
  15. for i := 0; i < b.N; i++ {
  16. _ = ac.Match("0.xray.com")
  17. }
  18. }
  19. func BenchmarkDomainMatcherGroup(b *testing.B) {
  20. g := new(DomainMatcherGroup)
  21. for i := 1; i <= 1024; i++ {
  22. g.Add(strconv.Itoa(i)+".example.com", uint32(i))
  23. }
  24. b.ResetTimer()
  25. for i := 0; i < b.N; i++ {
  26. _ = g.Match("0.example.com")
  27. }
  28. }
  29. func BenchmarkFullMatcherGroup(b *testing.B) {
  30. g := new(FullMatcherGroup)
  31. for i := 1; i <= 1024; i++ {
  32. g.Add(strconv.Itoa(i)+".example.com", uint32(i))
  33. }
  34. b.ResetTimer()
  35. for i := 0; i < b.N; i++ {
  36. _ = g.Match("0.example.com")
  37. }
  38. }
  39. func BenchmarkMarchGroup(b *testing.B) {
  40. g := new(MatcherGroup)
  41. for i := 1; i <= 1024; i++ {
  42. m, err := Domain.New(strconv.Itoa(i) + ".example.com")
  43. common.Must(err)
  44. g.Add(m)
  45. }
  46. b.ResetTimer()
  47. for i := 0; i < b.N; i++ {
  48. _ = g.Match("0.example.com")
  49. }
  50. }