From d7f6ef3a796267b4eb920ace54a775486678a321 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 31 May 2021 19:32:42 -0700 Subject: [PATCH] util/dnsname: add a benchmark for ToFQDN. Signed-off-by: David Anderson --- util/dnsname/dnsname_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/util/dnsname/dnsname_test.go b/util/dnsname/dnsname_test.go index 4867df2ac..b7f5afc1f 100644 --- a/util/dnsname/dnsname_test.go +++ b/util/dnsname/dnsname_test.go @@ -185,3 +185,24 @@ func TestTrimSuffix(t *testing.T) { } } } + +var sinkFQDN FQDN + +func BenchmarkToFQDN(b *testing.B) { + tests := []string{ + "www.tailscale.com.", + "www.tailscale.com", + ".www.tailscale.com", + "_ssh._tcp.www.tailscale.com.", + "_ssh._tcp.www.tailscale.com", + } + + for _, test := range tests { + b.Run(test, func(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + sinkFQDN, _ = ToFQDN(test) + } + }) + } +}