From 7d19718e1d437e078eabadf0127087ecc2287ccd Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 11 Mar 2022 12:18:41 +0300 Subject: [PATCH] [#168] netmap: Add simple selector benchmark Signed-off-by: Alex Vanin --- netmap/json_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/netmap/json_test.go b/netmap/json_test.go index 9ca0263c..1d0236bc 100644 --- a/netmap/json_test.go +++ b/netmap/json_test.go @@ -80,3 +80,27 @@ func TestPlacementPolicy_Interopability(t *testing.T) { }) } } +func BenchmarkManySelects(b *testing.B) { + testsFile := filepath.Join("json_tests", "many_selects.json") + bs, err := ioutil.ReadFile(testsFile) + require.NoError(b, err) + + var tc TestCase + require.NoError(b, json.Unmarshal(bs, &tc)) + tt, ok := tc.Tests["Select"] + require.True(b, ok) + + nodes := NodesFromInfo(tc.Nodes) + nm, err := NewNetmap(nodes) + require.NoError(b, err) + + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + _, err = nm.GetContainerNodes(&tt.Policy, tt.Pivot) + if err != nil { + b.FailNow() + } + } +}