Ekaterina Lebedeva
bd588fa2e5
All checks were successful
DCO action / DCO (pull_request) Successful in 41s
Tests and linters / Lint (pull_request) Successful in 1m11s
Tests and linters / Tests (1.22) (pull_request) Successful in 1m11s
Tests and linters / Tests (1.23) (pull_request) Successful in 1m10s
Tests and linters / Tests with -race (pull_request) Successful in 1m23s
Since Go 1.22 a `for` statement with a `range` clause is able to iterate through integer values from zero to an upper limit. gopatch script: @@ var i, e expression @@ -for i := 0; i <= e - 1; i++ { +for i := range e { ... } @@ var i, e expression @@ -for i := 0; i <= e; i++ { +for i := range e + 1 { ... } @@ var i, e expression @@ -for i := 0; i < e; i++ { +for i := range e { ... } Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
45 lines
854 B
Go
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()
|
|
}
|
|
}
|
|
})
|
|
}
|