From 9aac56d0d164e6ea4a4b1567752f165b9e93eac8 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 24 Oct 2025 08:37:49 +0200 Subject: [PATCH] oulet/routing: fix RIB lookup benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit b.N is not updated with the current loop count. Use a counter for that. See #351. ``` 08:37 ❱ go test -run='^$' -bench="BenchmarkRIBLookup" akvorado/outlet/routing/provider/bmp goos: linux goarch: amd64 pkg: akvorado/outlet/routing/provider/bmp cpu: AMD Ryzen 5 5600X 6-Core Processor BenchmarkRIBLookup/1000_routes,_1_peers-12 68083086 16.70 ns/op BenchmarkRIBLookup/1000_routes,_2_peers-12 70699065 17.29 ns/op BenchmarkRIBLookup/1000_routes,_5_peers-12 71537038 17.39 ns/op BenchmarkRIBLookup/10000_routes,_1_peers-12 60138338 18.91 ns/op BenchmarkRIBLookup/10000_routes,_2_peers-12 60308262 19.59 ns/op BenchmarkRIBLookup/10000_routes,_5_peers-12 50109068 23.59 ns/op BenchmarkRIBLookup/100000_routes,_1_peers-12 30180804 39.37 ns/op BenchmarkRIBLookup/100000_routes,_2_peers-12 26725899 41.08 ns/op BenchmarkRIBLookup/100000_routes,_5_peers-12 28283074 41.47 ns/op BenchmarkRIBLookup/1000000_routes,_1_peers-12 15247650 72.55 ns/op BenchmarkRIBLookup/1000000_routes,_2_peers-12 13945797 101.2 ns/op BenchmarkRIBLookup/1000000_routes,_5_peers-12 9414166 108.6 ns/op PASS ok akvorado/outlet/routing/provider/bmp 23.461s ``` --- outlet/routing/provider/bmp/prefixes_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/outlet/routing/provider/bmp/prefixes_test.go b/outlet/routing/provider/bmp/prefixes_test.go index 06d6dc31..e00c1a43 100644 --- a/outlet/routing/provider/bmp/prefixes_test.go +++ b/outlet/routing/provider/bmp/prefixes_test.go @@ -311,11 +311,13 @@ func BenchmarkRIBLookup(b *testing.B) { } } + count := 0 for b.Loop() { - ip4 := randomPrefixes[b.N%len(randomPrefixes)].Prefix.Addr() + count++ + ip4 := randomPrefixes[count%len(randomPrefixes)].Prefix.Addr() _, _ = rib.tree.Lookup(ip4) } - b.ReportMetric(float64(b.Elapsed())/float64(b.N), "ns/op") + b.ReportMetric(float64(b.Elapsed())/float64(count), "ns/op") }) } }