From 030ff2f122b1db83af4ae2b58c2b0e5175424e84 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 2 Jun 2023 14:50:04 +0300 Subject: [PATCH] [#87] netmap: Add benchmark for ContainerNodes() Signed-off-by: Evgenii Stratonikov --- netmap/bench_test.go | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 netmap/bench_test.go diff --git a/netmap/bench_test.go b/netmap/bench_test.go new file mode 100644 index 00000000..9793df6a --- /dev/null +++ b/netmap/bench_test.go @@ -0,0 +1,59 @@ +package netmap + +import ( + "testing" + + cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" + "github.com/stretchr/testify/require" +) + +func BenchmarkNetmap_ContainerNodes(b *testing.B) { + nodes := []NodeInfo{ + nodeInfoFromAttributes("Country", "Russia", "Order", "1"), + nodeInfoFromAttributes("Country", "Germany", "Order", "2"), + nodeInfoFromAttributes("Country", "Russia", "Order", "3"), + nodeInfoFromAttributes("Country", "France", "Order", "4"), + nodeInfoFromAttributes("Country", "France", "Order", "5"), + nodeInfoFromAttributes("Country", "Russia", "Order", "6"), + nodeInfoFromAttributes("Country", "Russia", "Order", "7"), + nodeInfoFromAttributes("Country", "Germany", "Order", "8"), + nodeInfoFromAttributes("Country", "Germany", "Order", "9"), + nodeInfoFromAttributes("Country", "Russia", "Order", "10"), + nodeInfoFromAttributes("Country", "China", "Order", "11"), + nodeInfoFromAttributes("Country", "China", "Order", "12"), + nodeInfoFromAttributes("Country", "Finland", "Order", "13"), + nodeInfoFromAttributes("Country", "Finland", "Order", "14"), + nodeInfoFromAttributes("Country", "España", "Order", "15"), + nodeInfoFromAttributes("Country", "España", "Order", "16"), + } + + var nm NetMap + nm.SetNodes(nodes) + + policies := []string{ + `REP 2`, + `REP 2 IN X CBF 2 SELECT 2 FROM * AS X`, + } + cnr := cidtest.ID() + + pivot := make([]byte, 32) + cnr.Encode(pivot) + + for i := range policies { + b.Run(policies[i], func(b *testing.B) { + var p PlacementPolicy + require.NoError(b, p.DecodeString(policies[i])) + + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + _, err := nm.ContainerNodes(p, pivot) + if err != nil { + b.Fatal(err) + } + } + + }) + } +}