From 58f2ef6085d9dcded9d9e4653991c51b521e3c8b Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 5 Jul 2021 21:21:52 -0700 Subject: [PATCH] util/deephash: add a benchmark and some benchmark data No code changes. Signed-off-by: Brad Fitzpatrick --- util/deephash/deephash_test.go | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/util/deephash/deephash_test.go b/util/deephash/deephash_test.go index 4b01e090f..f8c566959 100644 --- a/util/deephash/deephash_test.go +++ b/util/deephash/deephash_test.go @@ -75,6 +75,56 @@ func getVal() []interface{} { {2: 3}: true, {3: 4}: false, }, + &tailcfg.MapResponse{ + DERPMap: &tailcfg.DERPMap{ + Regions: map[int]*tailcfg.DERPRegion{ + 1: &tailcfg.DERPRegion{ + RegionID: 1, + RegionCode: "foo", + Nodes: []*tailcfg.DERPNode{ + { + Name: "n1", + RegionID: 1, + HostName: "foo.com", + }, + { + Name: "n2", + RegionID: 1, + HostName: "bar.com", + }, + }, + }, + }, + }, + DNSConfig: &tailcfg.DNSConfig{ + Resolvers: []tailcfg.DNSResolver{ + {Addr: "10.0.0.1"}, + }, + }, + PacketFilter: []tailcfg.FilterRule{ + { + SrcIPs: []string{"1.2.3.4"}, + DstPorts: []tailcfg.NetPortRange{ + { + IP: "1.2.3.4/32", + Ports: tailcfg.PortRange{1, 2}, + }, + }, + }, + }, + Peers: []*tailcfg.Node{ + { + ID: 1, + }, + { + ID: 2, + }, + }, + UserProfiles: []tailcfg.UserProfile{ + {ID: 1, LoginName: "foo@bar.com"}, + {ID: 2, LoginName: "bar@foo.com"}, + }, + }, } } @@ -139,6 +189,15 @@ func BenchmarkHashMapAcyclic(b *testing.B) { } } +func BenchmarkTailcfgNode(b *testing.B) { + b.ReportAllocs() + + node := new(tailcfg.Node) + for i := 0; i < b.N; i++ { + sink = Hash(node) + } +} + func TestExhaustive(t *testing.T) { seen := make(map[[sha256.Size]byte]bool) for i := 0; i < 100000; i++ {