mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-01 22:15:51 +00:00
net/dns/resolver: add nameFromQuery benchmark
To convince me it's not as alloc-y as it looks. Change-Id: I503a0cc267268a23d2973dfde9833c420be4e868 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
c7052154d5
commit
394c9de02b
@ -168,3 +168,25 @@ func TestMaxDoHInFlight(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkNameFromQuery(b *testing.B) {
|
||||||
|
builder := dns.NewBuilder(nil, dns.Header{})
|
||||||
|
builder.StartQuestions()
|
||||||
|
builder.Question(dns.Question{
|
||||||
|
Name: dns.MustNewName("foo.example."),
|
||||||
|
Type: dns.TypeA,
|
||||||
|
Class: dns.ClassINET,
|
||||||
|
})
|
||||||
|
msg, err := builder.Finish()
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
b.ReportAllocs()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
_, err := nameFromQuery(msg)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user