frostfs-api-go/refs/bench_test.go
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
[#113] go.mod: Use range over int
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>
2024-09-04 15:44:59 +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 range b.N {
raw := ObjectIDListToGRPCMessage(ids)
if len(raw) != len(ids) {
b.FailNow()
}
}
})
b.Run("from grpc message", func(b *testing.B) {
b.ReportAllocs()
for range b.N {
ids, err := ObjectIDListFromGRPCMessage(raw)
if err != nil || len(raw) != len(ids) {
b.FailNow()
}
}
})
b.Run("marshal", func(b *testing.B) {
b.ReportAllocs()
for range b.N {
buf := make([]byte, ObjectIDNestedListSize(1, ids))
n := ObjectIDNestedListMarshal(1, buf, ids)
if n != len(buf) {
b.FailNow()
}
}
})
}