AdGuardDNS/internal/ecscache/cache_internal_test.go
Andrey Meshkov f1791135af Sync v2.11.0
2024-12-05 14:19:25 +03:00

47 lines
877 B
Go

package ecscache
import (
"context"
"net/netip"
"testing"
"github.com/AdguardTeam/AdGuardDNS/internal/agdcache"
"github.com/AdguardTeam/AdGuardDNS/internal/dnsserver/dnsservertest"
"github.com/miekg/dns"
)
var msgSink *dns.Msg
func BenchmarkMiddleware_Get(b *testing.B) {
mw := &Middleware{
cache: agdcache.NewLRU[uint64, *cacheItem](&agdcache.LRUConfig{
Count: 10,
}),
ecsCache: agdcache.NewLRU[uint64, *cacheItem](&agdcache.LRUConfig{
Count: 10,
}),
}
const (
host = "benchmark.example"
fqdn = host + "."
)
req := dnsservertest.NewReq(fqdn, dns.TypeA, dns.ClassINET)
cr := &cacheRequest{
host: host,
subnet: netip.MustParsePrefix("1.2.3.0/24"),
qType: dns.TypeA,
qClass: dns.ClassINET,
reqDO: true,
}
ctx := context.Background()
b.ReportAllocs()
b.ResetTimer()
for range b.N {
msgSink, _ = mw.get(ctx, req, cr)
}
}