frostfs-api-go/refs/bench_test.go
Airat Arifullin 443098cb28
Some checks failed
DCO action / DCO (pull_request) Successful in 48s
Tests and linters / Tests (1.19) (pull_request) Failing after 59s
Tests and linters / Tests with -race (pull_request) Successful in 1m31s
Tests and linters / Tests (1.20) (pull_request) Failing after 5m52s
Tests and linters / Lint (pull_request) Successful in 7m3s
[#50] marshal: Use protowire append methods for marshalers
* Use protowire.AppendTag to encode a tag and append it
* Use protowire.AppendVarint to append numeric data
* Use protowire.AppendBytes and protowire.AppendString

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2023-08-31 12:12:43 +03:00

53 lines
1.1 KiB
Go

package refs
import (
"math/rand"
"strconv"
"testing"
)
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 := make([]ObjectID, size)
for i := range ids {
ids[i].val = make([]byte, 32)
rand.Read(ids[i].val)
}
raw := ObjectIDListToGRPCMessage(ids)
b.Run("to grpc message", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
raw := ObjectIDListToGRPCMessage(ids)
if len(raw) != len(ids) {
b.FailNow()
}
}
})
b.Run("from grpc message", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
ids, err := ObjectIDListFromGRPCMessage(raw)
if err != nil || len(raw) != len(ids) {
b.FailNow()
}
}
})
b.Run("marshal", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
buf := make([]byte, 0, ObjectIDNestedListSize(1, ids))
buf = ObjectIDNestedListMarshal(1, buf, ids)
if len(buf) != cap(buf) {
b.FailNow()
}
}
})
}