mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
derp: add a unique.Make-vs-local map benchmark
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>
This commit is contained in:
parent
6ff85846bc
commit
2c23f1aedc
@ -22,6 +22,7 @@
|
|||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
"unique"
|
||||||
|
|
||||||
"go4.org/mem"
|
"go4.org/mem"
|
||||||
"golang.org/x/time/rate"
|
"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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user