github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/acl/bench_test.go (about) 1 package acl_test 2 3 import ( 4 "testing" 5 6 "github.com/TrueCloudLab/frostfs-api-go/v2/acl" 7 aclGrpc "github.com/TrueCloudLab/frostfs-api-go/v2/acl/grpc" 8 acltest "github.com/TrueCloudLab/frostfs-api-go/v2/acl/test" 9 ) 10 11 func BenchmarkTable_ToGRPCMessage(b *testing.B) { 12 const size = 4 13 14 tb := new(acl.Table) 15 rs := make([]acl.Record, size) 16 for i := range rs { 17 fs := make([]acl.HeaderFilter, size) 18 for j := range fs { 19 fs[j] = *acltest.GenerateFilter(false) 20 } 21 ts := make([]acl.Target, size) 22 for j := range ts { 23 ts[j] = *acltest.GenerateTarget(false) 24 } 25 26 rs[i].SetFilters(fs) 27 rs[i].SetTargets(ts) 28 } 29 tb.SetRecords(rs) 30 31 raw := tb.ToGRPCMessage() 32 33 b.Run("to grpc message", func(b *testing.B) { 34 b.ReportAllocs() 35 for i := 0; i < b.N; i++ { 36 raw := tb.ToGRPCMessage() 37 if len(tb.GetRecords()) != len(raw.(*aclGrpc.EACLTable).Records) { 38 b.FailNow() 39 } 40 } 41 }) 42 b.Run("from grpc message", func(b *testing.B) { 43 b.ReportAllocs() 44 for i := 0; i < b.N; i++ { 45 tb := new(acl.Table) 46 if tb.FromGRPCMessage(raw) != nil { 47 b.FailNow() 48 } 49 } 50 }) 51 }