mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-16 09:26:21 -05:00
d4da365c5f
* Reorganize strmatcher's package structure * Rename types in strmatcher package according to their file names * Stablize strmatcher's Matcher interface * Implement []matcherEntry as SimpleMatcherGroup * Implement mph algorithm extracted from MphIndexMatcher as MphMatcherGroup * Implement AddMatcher/AddFullMatcher/AddDomainMatcher/AddSubstrMatcher for each MatcherGroup * Stablize strmatcher's MatcherGroup interface * Stablize strmatcher's IndexMatcher interface * Update strmatcher's benchmark * Compatibility fix for app/router's DomainMatcher condition * Fix code quality issue * Fix basic matcher issues * Update priority specification for Substr matcher
162 lines
3.4 KiB
Go
162 lines
3.4 KiB
Go
package strmatcher_test
|
|
|
|
import (
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common"
|
|
. "github.com/v2fly/v2ray-core/v4/common/strmatcher"
|
|
)
|
|
|
|
// Benchmark Domain Matcher Groups
|
|
|
|
func BenchmarkSimpleMatcherGroupForDomain(b *testing.B) {
|
|
g := new(SimpleMatcherGroup)
|
|
|
|
for i := 1; i <= 1024; i++ {
|
|
AddMatcherToGroup(g, DomainMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i))
|
|
}
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = g.Match("0.v2fly.org")
|
|
}
|
|
}
|
|
|
|
func BenchmarkDomainMatcherGroup(b *testing.B) {
|
|
g := new(DomainMatcherGroup)
|
|
|
|
for i := 1; i <= 1024; i++ {
|
|
AddMatcherToGroup(g, DomainMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i))
|
|
}
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = g.Match("0.v2fly.org")
|
|
}
|
|
}
|
|
|
|
func BenchmarkACAutomatonMatcherGroupForDomain(b *testing.B) {
|
|
ac := NewACAutomatonMatcherGroup()
|
|
for i := 1; i <= 1024; i++ {
|
|
AddMatcherToGroup(ac, DomainMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i))
|
|
}
|
|
ac.Build()
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = ac.MatchAny("0.v2fly.org")
|
|
}
|
|
}
|
|
|
|
func BenchmarkMphMatcherGroupForDomain(b *testing.B) {
|
|
mph := NewMphMatcherGroup()
|
|
for i := 1; i <= 1024; i++ {
|
|
AddMatcherToGroup(mph, DomainMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i))
|
|
}
|
|
mph.Build()
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = mph.MatchAny("0.v2fly.org")
|
|
}
|
|
}
|
|
|
|
// Benchmark Full Matcher Groups
|
|
|
|
func BenchmarkSimpleMatcherGroupForFull(b *testing.B) {
|
|
g := new(SimpleMatcherGroup)
|
|
|
|
for i := 1; i <= 1024; i++ {
|
|
AddMatcherToGroup(g, FullMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i))
|
|
}
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = g.Match("0.v2fly.org")
|
|
}
|
|
}
|
|
|
|
func BenchmarkFullMatcherGroup(b *testing.B) {
|
|
g := new(FullMatcherGroup)
|
|
|
|
for i := 1; i <= 1024; i++ {
|
|
AddMatcherToGroup(g, FullMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i))
|
|
}
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = g.Match("0.v2fly.org")
|
|
}
|
|
}
|
|
|
|
func BenchmarkACAutomatonMatcherGroupForFull(b *testing.B) {
|
|
ac := NewACAutomatonMatcherGroup()
|
|
for i := 1; i <= 1024; i++ {
|
|
AddMatcherToGroup(ac, FullMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i))
|
|
}
|
|
ac.Build()
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = ac.MatchAny("0.v2fly.org")
|
|
}
|
|
}
|
|
|
|
func BenchmarkMphMatcherGroupFull(b *testing.B) {
|
|
mph := NewMphMatcherGroup()
|
|
for i := 1; i <= 1024; i++ {
|
|
AddMatcherToGroup(mph, FullMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i))
|
|
}
|
|
mph.Build()
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = mph.MatchAny("0.v2fly.org")
|
|
}
|
|
}
|
|
|
|
// Benchmark Substr Matcher Groups
|
|
|
|
func BenchmarkSimpleMatcherGroupForSubstr(b *testing.B) {
|
|
g := new(SimpleMatcherGroup)
|
|
|
|
for i := 1; i <= 1024; i++ {
|
|
AddMatcherToGroup(g, SubstrMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i))
|
|
}
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = g.Match("0.v2fly.org")
|
|
}
|
|
}
|
|
|
|
func BenchmarkACAutomatonMatcherGroupForSubstr(b *testing.B) {
|
|
ac := NewACAutomatonMatcherGroup()
|
|
for i := 1; i <= 1024; i++ {
|
|
AddMatcherToGroup(ac, SubstrMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i))
|
|
}
|
|
ac.Build()
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = ac.MatchAny("0.v2fly.org")
|
|
}
|
|
}
|
|
|
|
// Benchmark Index Matchers
|
|
|
|
func BenchmarkLinearIndexMatcher(b *testing.B) {
|
|
g := new(LinearIndexMatcher)
|
|
for i := 1; i <= 1024; i++ {
|
|
m, err := Domain.New(strconv.Itoa(i) + ".v2fly.org")
|
|
common.Must(err)
|
|
g.Add(m)
|
|
}
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = g.Match("0.v2fly.org")
|
|
}
|
|
}
|