mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
wgengine/wglog: add BenchmarkSetPeer
Because it showed up on hello profiles. Cycle through some moderate-sized sets of peers. This should cover the "small tweaks to netmap" and the "up/down cycle" cases. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
parent
36a26e6a71
commit
9356912053
@ -8,6 +8,7 @@
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/types/wgkey"
|
||||
"tailscale.com/wgengine/wgcfg"
|
||||
"tailscale.com/wgengine/wglog"
|
||||
@ -70,3 +71,30 @@ func stringer(s string) stringerString {
|
||||
type stringerString string
|
||||
|
||||
func (s stringerString) String() string { return string(s) }
|
||||
|
||||
func BenchmarkSetPeers(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
x := wglog.NewLogger(logger.Discard)
|
||||
peers := [][]wgcfg.Peer{genPeers(0), genPeers(15), genPeers(16), genPeers(15)}
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, p := range peers {
|
||||
x.SetPeers(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func genPeers(n int) []wgcfg.Peer {
|
||||
if n > 32 {
|
||||
panic("too many peers")
|
||||
}
|
||||
if n == 0 {
|
||||
return nil
|
||||
}
|
||||
peers := make([]wgcfg.Peer, n)
|
||||
for i := range peers {
|
||||
var k wgkey.Key
|
||||
k[n] = byte(n)
|
||||
peers[i].PublicKey = k
|
||||
}
|
||||
return peers
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user