Skip to content

Commit

Permalink
[nspcc-dev#1460] meta: Add a benchmark on Get operation
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell authored and aprasolova committed Oct 19, 2022
1 parent ba48b7b commit 94ec34e
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions pkg/local_object_storage/metabase/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package meta_test

import (
"bytes"
"fmt"
"os"
"testing"

"github.com/nspcc-dev/neofs-node/pkg/core/object"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -149,3 +152,54 @@ func binaryEqual(a, b *objectSDK.Object) bool {

return bytes.Equal(binaryA, binaryB)
}

func BenchmarkGet(b *testing.B) {
numOfObjects := [...]int{
1,
10,
100,
}

for _, num := range numOfObjects {
b.Run(fmt.Sprintf("%d objects", num), func(b *testing.B) {
benchmarkGet(b, num)
})
}
}

var obj *objectSDK.Object

func benchmarkGet(b *testing.B, numOfObj int) {
db := newDB(b)
addrs := make([]oid.Address, 0, numOfObj)

for i := 0; i < numOfObj; i++ {
raw := generateObject(b)
addrs = append(addrs, object.AddressOf(raw))

err := putBig(db, raw)
require.NoError(b, err)
}

b.Cleanup(func() {
_ = db.Close()
_ = os.RemoveAll(b.Name())
})
b.ReportAllocs()
b.ResetTimer()

var getPrm meta.GetPrm
getPrm.WithAddress(addrs[len(addrs)/2])

for i := 0; i < b.N; i++ {
for _, addr := range addrs {
getPrm.WithAddress(addr)

res, err := db.Get(getPrm)
require.NoError(b, err)

obj = res.Header()
}

}
}

0 comments on commit 94ec34e

Please sign in to comment.