From 77a573caf1bf4096fe445dc10ecaf837f90f4eb6 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Wed, 5 May 2021 13:50:56 +0100 Subject: [PATCH] refactor test for loader benchmark --- infra/conf/geodata/geodata_test.go | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/infra/conf/geodata/geodata_test.go b/infra/conf/geodata/geodata_test.go index 581dc05c3..74e515e8d 100644 --- a/infra/conf/geodata/geodata_test.go +++ b/infra/conf/geodata/geodata_test.go @@ -107,3 +107,52 @@ func BenchmarkMemconservativeLoaderGeoSite(b *testing.B) { b.ReportMetric(float64(m4.Alloc-m3.Alloc)/1024, "KiB(GeoSite-Alloc)") b.ReportMetric(float64(m4.TotalAlloc-m3.TotalAlloc)/1024/1024, "MiB(GeoSite-TotalAlloc)") } + +func BenchmarkAllLoader(b *testing.B) { + type testingProfileForLoader struct { + name string + } + testCase := []testingProfileForLoader{ + {"standard"}, + {"memconservative"}, + } + for _, v := range testCase { + b.Run(v.name, func(b *testing.B) { + b.Run("Geosite", func(b *testing.B) { + loader, err := geodata.GetGeoDataLoader(v.name) + if err != nil { + b.Fatal(err) + } + + m3 := runtime.MemStats{} + m4 := runtime.MemStats{} + runtime.ReadMemStats(&m3) + loader.LoadGeoSite("cn") + loader.LoadGeoSite("geolocation-!cn") + loader.LoadGeoSite("private") + runtime.ReadMemStats(&m4) + + b.ReportMetric(float64(m4.Alloc-m3.Alloc)/1024, "KiB(GeoSite-Alloc)") + b.ReportMetric(float64(m4.TotalAlloc-m3.TotalAlloc)/1024/1024, "MiB(GeoSite-TotalAlloc)") + }) + + b.Run("GeoIP", func(b *testing.B) { + loader, err := geodata.GetGeoDataLoader(v.name) + if err != nil { + b.Fatal(err) + } + + m1 := runtime.MemStats{} + m2 := runtime.MemStats{} + runtime.ReadMemStats(&m1) + loader.LoadGeoIP("cn") + loader.LoadGeoIP("us") + loader.LoadGeoIP("private") + runtime.ReadMemStats(&m2) + + b.ReportMetric(float64(m2.Alloc-m1.Alloc)/1024/1024, "MiB(GeoIP-Alloc)") + b.ReportMetric(float64(m2.TotalAlloc-m1.TotalAlloc)/1024/1024, "MiB(GeoIP-TotalAlloc)") + }) + }) + } +}