mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
orchestrator/geoip: add a benchmark for Iterate*Databases()
Now:
```
goos: linux
goarch: amd64
pkg: akvorado/orchestrator/geoip
cpu: AMD Ryzen 7 PRO 6850U with Radeon Graphics
BenchmarkIterDatabase/ASN-16 3376 457.0 ns/entry
BenchmarkIterDatabase/GeoIP-16 2410 754.5 ns/entry
```
Before 0a10764cc9:
```
goos: linux
goarch: amd64
pkg: akvorado/orchestrator/geoip
cpu: AMD Ryzen 7 PRO 6850U with Radeon Graphics
BenchmarkIterDatabase/ASN-16 2863 609.3 ns/entry
BenchmarkIterDatabase/GeoIP-16 3286 719.3 ns/entry
```
I was hoping for a bit more!
This commit is contained in:
@@ -18,7 +18,7 @@ type MockComponent struct {
|
||||
}
|
||||
|
||||
// NewMock will create a daemon component that does nothing.
|
||||
func NewMock(t *testing.T) Component {
|
||||
func NewMock(t testing.TB) Component {
|
||||
t.Helper()
|
||||
return &MockComponent{
|
||||
lifecycleComponent: lifecycleComponent{
|
||||
|
||||
@@ -103,7 +103,7 @@ func CheckExternalService(t *testing.T, name string, candidates []string) string
|
||||
}
|
||||
|
||||
// StartStop starts a component and stops it on cleanup.
|
||||
func StartStop(t *testing.T, component any) {
|
||||
func StartStop(t testing.TB, component any) {
|
||||
t.Helper()
|
||||
if starterC, ok := component.(starter); ok {
|
||||
if err := starterC.Start(); err != nil {
|
||||
|
||||
@@ -13,6 +13,35 @@ import (
|
||||
"akvorado/common/reporter"
|
||||
)
|
||||
|
||||
func BenchmarkIterDatabase(b *testing.B) {
|
||||
r := reporter.NewMock(b)
|
||||
c := NewMock(b, r, true)
|
||||
|
||||
b.Run("ASN", func(b *testing.B) {
|
||||
entries := 0
|
||||
for b.Loop() {
|
||||
c.IterASNDatabases(func(netip.Prefix, ASNInfo) error {
|
||||
entries++
|
||||
return nil
|
||||
})
|
||||
}
|
||||
b.ReportMetric(0, "ns/op")
|
||||
b.ReportMetric(float64(b.Elapsed())/float64(entries), "ns/entry")
|
||||
})
|
||||
|
||||
b.Run("GeoIP", func(b *testing.B) {
|
||||
entries := 0
|
||||
for b.Loop() {
|
||||
c.IterGeoDatabases(func(netip.Prefix, GeoInfo) error {
|
||||
entries++
|
||||
return nil
|
||||
})
|
||||
}
|
||||
b.ReportMetric(0, "ns/op")
|
||||
b.ReportMetric(float64(b.Elapsed())/float64(entries), "ns/entry")
|
||||
})
|
||||
}
|
||||
|
||||
func TestIterDatabase(t *testing.T) {
|
||||
r := reporter.NewMock(t)
|
||||
c := NewMock(t, r, true)
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
// available here:
|
||||
// - https://github.com/maxmind/MaxMind-DB/blob/main/source-data/GeoLite2-ASN-Test.json
|
||||
// - https://github.com/maxmind/MaxMind-DB/blob/main/source-data/GeoLite2-Country-Test.json
|
||||
func NewMock(t *testing.T, r *reporter.Reporter, withData bool) *Component {
|
||||
func NewMock(t testing.TB, r *reporter.Reporter, withData bool) *Component {
|
||||
t.Helper()
|
||||
config := DefaultConfiguration()
|
||||
_, src, _, _ := runtime.Caller(0)
|
||||
|
||||
Reference in New Issue
Block a user