mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-10-10 04:03:11 +08:00
chore: sharing synthetic datasets used for build benchmarking
This commit is contained in:
@@ -536,7 +536,7 @@ type domainMapBenchmarkQuery struct {
|
||||
found bool
|
||||
}
|
||||
|
||||
func domainMapBenchmarkDomains(count int) []string {
|
||||
func domainMapLookupDomains(count int) []string {
|
||||
domains := make([]string, count)
|
||||
for index := range domains {
|
||||
domain := "host" + strconv.Itoa(index) + ".example.com"
|
||||
@@ -558,7 +558,7 @@ func domainMapBenchmarkDomains(count int) []string {
|
||||
|
||||
func BenchmarkDomainMapLookup(benchmark *testing.B) {
|
||||
const deepDomain = "api.service.region.cluster.internal.prod.company.example.com"
|
||||
domains := append(domainMapBenchmarkDomains(10000),
|
||||
domains := append(domainMapLookupDomains(10000),
|
||||
"*.*.overlap.example.com",
|
||||
"dead.*.a.overlap.example.com",
|
||||
"dead.b.a.overlap.example.com",
|
||||
@@ -668,7 +668,7 @@ func benchmarkDomainMapLookup[T any](benchmark *testing.B, domains []string, que
|
||||
|
||||
func BenchmarkDomainMapBuild(benchmark *testing.B) {
|
||||
for _, count := range []int{100, 10000} {
|
||||
domains := domainMapBenchmarkDomains(count)
|
||||
domains := domainBuildBenchmarkDomains(count)
|
||||
benchmark.Run(fmt.Sprintf("%d/map", count), func(benchmark *testing.B) {
|
||||
benchmark.ReportAllocs()
|
||||
var before, after runtime.MemStats
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package trie_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -297,7 +298,15 @@ func BenchmarkDomainSetHas(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDomainSetBuild(b *testing.B) {
|
||||
func domainBenchmarkHash(value uint32) uint32 {
|
||||
value ^= value >> 16
|
||||
value *= 0x7feb352d
|
||||
value ^= value >> 15
|
||||
value *= 0x846ca68b
|
||||
return value ^ (value >> 16)
|
||||
}
|
||||
|
||||
func domainBuildBenchmarkDomains(count int) []string {
|
||||
suffixes := [...]string{
|
||||
"google.com",
|
||||
"github.io",
|
||||
@@ -307,26 +316,47 @@ func BenchmarkDomainSetBuild(b *testing.B) {
|
||||
"apple.com",
|
||||
"telegram.org",
|
||||
"example.co.uk",
|
||||
"example.com.au",
|
||||
"example.com.tw",
|
||||
"example.co.jp",
|
||||
"example.de",
|
||||
}
|
||||
domains := make([]string, 10000)
|
||||
for i := range domains {
|
||||
domain := strconv.Itoa(i) + "." + suffixes[i%len(suffixes)]
|
||||
switch i % 20 {
|
||||
hosts := [...]string{
|
||||
"api%d",
|
||||
"cdn%d",
|
||||
"img%d",
|
||||
"static-%d",
|
||||
"region-%d",
|
||||
"production-download-%d",
|
||||
"service%d.edge",
|
||||
"download%d.assets.eu-west-1",
|
||||
}
|
||||
domains := make([]string, count)
|
||||
for index := range domains {
|
||||
hash := domainBenchmarkHash(uint32(index))
|
||||
if index > 0 && hash%50 == 0 {
|
||||
domains[index] = domains[int(uint64(hash>>8)%uint64(index))]
|
||||
continue
|
||||
}
|
||||
domain := fmt.Sprintf(hosts[(hash>>8)%uint32(len(hosts))], index) + "." + suffixes[(hash>>12)%uint32(len(suffixes))]
|
||||
switch (hash >> 24) % 20 {
|
||||
case 0:
|
||||
domains[i] = domain
|
||||
domains[index] = domain
|
||||
case 1:
|
||||
domains[i] = "." + domain
|
||||
domains[index] = "." + domain
|
||||
case 2:
|
||||
domains[i] = "*." + domain
|
||||
domains[index] = "*." + domain
|
||||
case 3:
|
||||
domains[i] = "stun.*." + domain
|
||||
domains[index] = "service.*." + domain
|
||||
default:
|
||||
domains[i] = "+." + domain
|
||||
}
|
||||
if i%50 == 49 {
|
||||
domains[i] = domains[i-1]
|
||||
domains[index] = "+." + domain
|
||||
}
|
||||
}
|
||||
return domains
|
||||
}
|
||||
|
||||
func BenchmarkDomainSetBuild(b *testing.B) {
|
||||
domains := domainBuildBenchmarkDomains(10000)
|
||||
|
||||
b.Run("via_trie", func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
Reference in New Issue
Block a user