frostfs-api-go/acl/bench_test.go
Evgenii Stratonikov ec484f2fd2 [#376] acl: Replace slices of pointers with raw structs
```
name                                     old time/op    new time/op    delta
Table_ToGRPCMessage/to_grpc_message-8      2.82µs ± 5%    2.86µs ± 5%     ~     (p=0.395 n=10+8)
Table_ToGRPCMessage/from_grpc_message-8    2.47µs ± 5%    1.08µs ± 6%  -56.16%  (p=0.000 n=9+9)

name                                     old alloc/op   new alloc/op   delta
Table_ToGRPCMessage/to_grpc_message-8      3.31kB ± 0%    3.31kB ± 0%     ~     (all equal)
Table_ToGRPCMessage/from_grpc_message-8    1.82kB ± 0%    1.38kB ± 0%  -24.56%  (p=0.000 n=10+10)

name                                     old allocs/op  new allocs/op  delta
Table_ToGRPCMessage/to_grpc_message-8        46.0 ± 0%      46.0 ± 0%     ~     (all equal)
Table_ToGRPCMessage/from_grpc_message-8      45.0 ± 0%       9.0 ± 0%  -80.00%  (p=0.000 n=10+10)
```

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2022-03-15 12:19:49 +03:00

51 lines
1 KiB
Go

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].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()
}
}
})
}