[#376] acl: Add benchmarks for Table
conversions
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
84daaf59ef
commit
4a70c42104
1 changed files with 52 additions and 0 deletions
52
acl/bench_test.go
Normal file
52
acl/bench_test.go
Normal file
|
@ -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()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue