github.com/imannamdari/v2ray-core/v5@v5.0.5/common/strmatcher/benchmark_indexmatcher_test.go (about)

     1  package strmatcher_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	. "github.com/imannamdari/v2ray-core/v5/common/strmatcher"
     7  )
     8  
     9  func BenchmarkLinearIndexMatcher(b *testing.B) {
    10  	benchmarkIndexMatcher(b, func() IndexMatcher {
    11  		return NewLinearIndexMatcher()
    12  	})
    13  }
    14  
    15  func BenchmarkMphIndexMatcher(b *testing.B) {
    16  	benchmarkIndexMatcher(b, func() IndexMatcher {
    17  		return NewMphIndexMatcher()
    18  	})
    19  }
    20  
    21  func benchmarkIndexMatcher(b *testing.B, ctor func() IndexMatcher) {
    22  	b.Run("Match", func(b *testing.B) {
    23  		b.Run("Domain------------", func(b *testing.B) {
    24  			benchmarkMatch(b, ctor(), map[Type]bool{Domain: true})
    25  		})
    26  		b.Run("Domain+Full-------", func(b *testing.B) {
    27  			benchmarkMatch(b, ctor(), map[Type]bool{Domain: true, Full: true})
    28  		})
    29  		b.Run("Domain+Full+Substr", func(b *testing.B) {
    30  			benchmarkMatch(b, ctor(), map[Type]bool{Domain: true, Full: true, Substr: true})
    31  		})
    32  		b.Run("All-Fail----------", func(b *testing.B) {
    33  			benchmarkMatch(b, ctor(), map[Type]bool{Domain: false, Full: false, Substr: false})
    34  		})
    35  	})
    36  	b.Run("Match/Dotless", func(b *testing.B) { // Dotless domain matcher automatically inserted in DNS app when "localhost" DNS is used.
    37  		b.Run("All-Succ", func(b *testing.B) {
    38  			benchmarkMatch(b, ctor(), map[Type]bool{Domain: true, Full: true, Substr: true, Regex: true})
    39  		})
    40  		b.Run("All-Fail", func(b *testing.B) {
    41  			benchmarkMatch(b, ctor(), map[Type]bool{Domain: false, Full: false, Substr: false, Regex: false})
    42  		})
    43  	})
    44  	b.Run("MatchAny", func(b *testing.B) {
    45  		b.Run("First-Full--", func(b *testing.B) {
    46  			benchmarkMatchAny(b, ctor(), map[Type]bool{Full: true, Domain: true, Substr: true})
    47  		})
    48  		b.Run("First-Domain", func(b *testing.B) {
    49  			benchmarkMatchAny(b, ctor(), map[Type]bool{Full: false, Domain: true, Substr: true})
    50  		})
    51  		b.Run("First-Substr", func(b *testing.B) {
    52  			benchmarkMatchAny(b, ctor(), map[Type]bool{Full: false, Domain: false, Substr: true})
    53  		})
    54  		b.Run("All-Fail----", func(b *testing.B) {
    55  			benchmarkMatchAny(b, ctor(), map[Type]bool{Full: false, Domain: false, Substr: false})
    56  		})
    57  	})
    58  }