From 478fd59674c5fc9526d0b57c62ffac7388c2bab7 Mon Sep 17 00:00:00 2001 From: sukun Date: Sun, 8 Dec 2024 14:06:44 +0530 Subject: [PATCH] improve GetAndClearAddrs benchmark --- p2p/host/peerstore/test/benchmarks_suite.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/p2p/host/peerstore/test/benchmarks_suite.go b/p2p/host/peerstore/test/benchmarks_suite.go index 8fc1f4fc7e..01669a1b2d 100644 --- a/p2p/host/peerstore/test/benchmarks_suite.go +++ b/p2p/host/peerstore/test/benchmarks_suite.go @@ -36,11 +36,20 @@ func BenchmarkPeerstore(b *testing.B, factory PeerstoreFactory, variant string) ps, cleanup := factory() defer cleanup() b.ResetTimer() + itersPerBM := 10 for i := 0; i < b.N; i++ { - pp := peers[i%N] - ps.AddAddrs(pp.ID, pp.Addr, pstore.RecentlyConnectedAddrTTL) - ps.Addrs(pp.ID) - ps.ClearAddrs(pp.ID) + for j := 0; j < itersPerBM; j++ { + pp := peers[(i+j)%N] + ps.AddAddrs(pp.ID, pp.Addr, pstore.RecentlyConnectedAddrTTL) + } + for j := 0; j < itersPerBM; j++ { + pp := peers[(i+j)%N] + ps.Addrs(pp.ID) + } + for j := 0; j < itersPerBM; j++ { + pp := peers[(i+j)%N] + ps.ClearAddrs(pp.ID) + } } })