From 4a70c4210472c98ee85b58e52876043287f526dd Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 1 Mar 2022 16:22:10 +0300 Subject: [PATCH] [#376] acl: Add benchmarks for `Table` conversions Signed-off-by: Evgenii Stratonikov --- acl/bench_test.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 acl/bench_test.go diff --git a/acl/bench_test.go b/acl/bench_test.go new file mode 100644 index 0000000..54ec186 --- /dev/null +++ b/acl/bench_test.go @@ -0,0 +1,52 @@ +package acl_test + +import ( + "testing" + + "github.com/nspcc-dev/neofs-api-go/v2/acl" + aclGrpc "github.com/nspcc-dev/neofs-api-go/v2/acl/grpc" + acltest "github.com/nspcc-dev/neofs-api-go/v2/acl/test" +) + +func BenchmarkTable_ToGRPCMessage(b *testing.B) { + const size = 4 + + tb := new(acl.Table) + rs := make([]*acl.Record, size) + for i := range rs { + fs := make([]*acl.HeaderFilter, size) + for j := range fs { + fs[j] = acltest.GenerateFilter(false) + } + ts := make([]*acl.Target, size) + for j := range ts { + ts[j] = acltest.GenerateTarget(false) + } + + rs[i] = new(acl.Record) + rs[i].SetFilters(fs) + rs[i].SetTargets(ts) + } + tb.SetRecords(rs) + + raw := tb.ToGRPCMessage() + + b.Run("to grpc message", func(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + raw := tb.ToGRPCMessage() + if len(tb.GetRecords()) != len(raw.(*aclGrpc.EACLTable).Records) { + b.FailNow() + } + } + }) + b.Run("from grpc message", func(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + tb := new(acl.Table) + if tb.FromGRPCMessage(raw) != nil { + b.FailNow() + } + } + }) +}