diff --git a/derp/derp_test.go b/derp/derp_test.go index 9185194dd..436dd6d2e 100644 --- a/derp/derp_test.go +++ b/derp/derp_test.go @@ -22,6 +22,7 @@ "sync" "testing" "time" + "unique" "go4.org/mem" "golang.org/x/time/rate" @@ -1598,3 +1599,40 @@ func TestServerRepliesToPing(t *testing.T) { } } } + +func BenchmarkUnique(b *testing.B) { + var key [32]byte + for i := range key { + key[i] = byte(i) + } + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + h := unique.Make(key) + if h.Value() != key { + b.Fatal("unexpected") + } + } + }) +} + +func BenchmarkLocalMap(b *testing.B) { + var key [32]byte + for i := range key { + key[i] = byte(i) + } + m := map[[32]byte]bool{ + key: true, + } + k2 := key + for i := range k2 { + k2[0] = byte(i + 1) + m[k2] = false + } + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + if !m[key] { + b.Fatal("unexpected") + } + } + }) +}