frostfs-api-go/refs/bench_test.go

42 lines
848 B
Go
Raw Permalink Normal View History

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