func BenchmarkGetMsgFromCacheHit(b *testing.B) {
	cache := Config{}.newCache()
	req := new(D.Msg)
	req.SetQuestion("example.com.", D.TypeA)
	resp := new(D.Msg)
	resp.SetReply(req)
	resp.Answer = []D.RR{&D.A{
		Hdr: D.RR_Header{Name: "example.com.", Rrtype: D.TypeA, Class: D.ClassINET, Ttl: 300},
		A:   net.IPv4(192, 0, 2, 1).To4(),
	}}
	putMsgToCache(cache, req.Question[0], resp)

	q := req.Question[0]
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		msg, _, hit := getMsgFromCache(cache, q)
		if !hit || msg == nil {
			b.Fatal("cache miss")
		}
	}
}

func BenchmarkExchangeContextCacheHit(b *testing.B) {
	r, req := cachedAResolver(b)
	ctx := context.Background()
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		msg, err := r.ExchangeContext(ctx, req)
		if err != nil || msg == nil {
			b.Fatalf("ExchangeContext: %v", err)
		}
	}
}

func BenchmarkLookupIPv4CacheHit(b *testing.B) {
	r, _ := cachedAResolver(b)
	ctx := context.Background()
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		ips, err := r.LookupIPv4(ctx, "warm.example")
		if err != nil || len(ips) != 1 {
			b.Fatalf("LookupIPv4: %v %v", ips, err)
		}
	}
}