[#276] Merge repo with frostfs-api-go
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
This commit is contained in:
parent
5361f0eceb
commit
6ce73790ea
337 changed files with 66666 additions and 283 deletions
45
api/object/bench_test.go
Normal file
45
api/object/bench_test.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
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()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue