github.com/EagleQL/Xray-core@v1.4.3/common/strmatcher/benchmark_test.go (about)

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