frostfs-api-go/refs/bench_test.go
Airat Arifullin bc16a32c24 [#40] types: Generate StableMarshaler/StableSize methods for protobufs
* Add plugin option for protogen in Makefile
* Fix the generator for the plugin in util/protogen
* Erase convertable types, move helpful methods to gRPC protobufs
* Erase helpers for convertations
* Generate StableMarshlal/StableSize for protobufs by the protoc plugin

Signed-off-by: Airat Arifullin a.arifullin@yadro.com
2023-07-10 12:08:48 +03:00

41 lines
848 B
Go

package refs
import (
"strconv"
"testing"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
)
func BenchmarkObjectIDSlice(b *testing.B) {
for _, size := range []int{0, 1, 50} {
b.Run(strconv.Itoa(size)+" elements", func(b *testing.B) {
benchmarkObjectIDSlice(b, size)
})
}
}
func benchmarkObjectIDSlice(b *testing.B, size int) {
ids := refstest.GenerateObjectIDs(false)
b.Run("marshal", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
size := 0
for _, id := range ids {
size += proto.NestedStructureSize(9, id)
}
buf := make([]byte, size)
offset := 0
for _, id := range ids {
offset += proto.NestedStructureMarshal(9, buf[offset:], id)
}
if offset != len(buf) {
b.FailNow()
}
}
})
}