summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@tailscale.com>2024-11-09 14:51:21 -0800
committerBrad Fitzpatrick <bradfitz@tailscale.com>2024-11-09 14:51:21 -0800
commit2c23f1aedc51c9f816349eb4a24439dbf24484ea (patch)
treeec2bb0152aeef64f8bc38f959d9b015a9ef8708f
parent6ff85846bcb5c8aeb35e2fa36808366ec4f148fb (diff)
downloadtailscale-bradfitz/bench.tar.xz
tailscale-bradfitz/bench.zip
derp: add a unique.Make-vs-local map benchmarkbradfitz/bench
goos: darwin goarch: arm64 pkg: tailscale.com/derp cpu: Apple M1 BenchmarkUnique-8 139699720 10.59 ns/op BenchmarkUnique-8 138409840 8.619 ns/op BenchmarkUnique-8 134697708 8.521 ns/op BenchmarkUnique-8 136568799 8.653 ns/op BenchmarkUnique-8 134478981 8.647 ns/op BenchmarkLocalMap-8 675015452 1.643 ns/op BenchmarkLocalMap-8 717245598 1.648 ns/op BenchmarkLocalMap-8 697626253 1.657 ns/op BenchmarkLocalMap-8 729024962 1.670 ns/op BenchmarkLocalMap-8 712870580 1.668 ns/op PASS ok tailscale.com/derp 19.038s Updates tailscale/corp#24485 Change-Id: Ie8008b07c8c4625cf2b83e38eff169e2248b2d05 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
-rw-r--r--derp/derp_test.go38
1 files changed, 38 insertions, 0 deletions
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 @@ import (
"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")
+ }
+ }
+ })
+}