frostfs-sdk-go/api/object/bench_test.go
Pavel Pogodaev 6ce73790ea
All checks were successful
DCO / DCO (pull_request) Successful in 38s
Tests and linters / Tests (pull_request) Successful in 1m13s
Tests and linters / Lint (pull_request) Successful in 2m36s
[#276] Merge repo with frostfs-api-go
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
2024-10-22 14:05:12 +00:00

45 lines
854 B
Go

package object
import (
"math/rand"
"testing"
"github.com/stretchr/testify/require"
)
func randString(n int) string {
x := make([]byte, n)
for i := range x {
x[i] = byte('a' + rand.Intn('z'-'a'))
}
return string(x)
}
func BenchmarkAttributesMarshal(b *testing.B) {
attrs := make([]Attribute, 50)
for i := range attrs {
attrs[i].key = SysAttributePrefix + randString(10)
attrs[i].val = randString(10)
}
raw := AttributesToGRPC(attrs)
require.Equal(b, len(raw), len(attrs))
b.Run("marshal", func(b *testing.B) {
b.ReportAllocs()
for range b.N {
res := AttributesToGRPC(attrs)
if len(res) != len(raw) {
b.FailNow()
}
}
})
b.Run("unmarshal", func(b *testing.B) {
b.ReportAllocs()
for range b.N {
res, err := AttributesFromGRPC(raw)
if err != nil || len(res) != len(raw) {
b.FailNow()
}
}
})
}