mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-01-31 05:20:07 +08:00
add a benchmark for lookahead cycles.
This commit is contained in:
parent
e43a2fc519
commit
a306a6eadb
@ -172,3 +172,34 @@ func TestGCDelay(t *testing.T) {
|
|||||||
t.Errorf("expected 1 lookahead entry, got: %d", i)
|
t.Errorf("expected 1 lookahead entry, got: %d", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkLookaheadCycle(b *testing.B) {
|
||||||
|
ids := test.GeneratePeerIDs(100)
|
||||||
|
addrs := test.GenerateAddrs(100)
|
||||||
|
|
||||||
|
opts := DefaultOpts()
|
||||||
|
|
||||||
|
opts.GCInitialDelay = 2 * time.Hour
|
||||||
|
opts.GCLookaheadInterval = 2 * time.Hour
|
||||||
|
opts.GCPurgeInterval = 6 * time.Hour
|
||||||
|
|
||||||
|
factory := addressBookFactory(b, badgerStore, opts)
|
||||||
|
ab, closeFn := factory()
|
||||||
|
defer closeFn()
|
||||||
|
|
||||||
|
inside, outside := 1*time.Minute, 48*time.Hour
|
||||||
|
for i, id := range ids {
|
||||||
|
var ttl time.Duration
|
||||||
|
if i%2 == 0 {
|
||||||
|
ttl = inside
|
||||||
|
} else {
|
||||||
|
ttl = outside
|
||||||
|
}
|
||||||
|
ab.AddAddrs(id, addrs, ttl)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
ab.(*dsAddrBook).populateLookahead()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user