oulet/routing: fix RIB lookup benchmark
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Nix dependency hashes / Update dependency hashes (push) Has been cancelled

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
```
This commit is contained in:
Vincent Bernat
2025-10-24 08:37:49 +02:00
parent 10bf6a956b
commit 9aac56d0d1

View File

@@ -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")
})
}
}