forked from TrueCloudLab/frostfs-node
[#135] metabase: Implement benchmarking tests
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
1db01725c9
commit
a61f8d44d1
4 changed files with 377 additions and 0 deletions
66
pkg/local_object_storage/metabase/get_test.go
Normal file
66
pkg/local_object_storage/metabase/get_test.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package meta
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
func BenchmarkDB_Get(b *testing.B) {
|
||||
path := "get_test.db"
|
||||
|
||||
bdb, err := bbolt.Open(path, 0600, nil)
|
||||
require.NoError(b, err)
|
||||
|
||||
defer func() {
|
||||
bdb.Close()
|
||||
os.Remove(path)
|
||||
}()
|
||||
|
||||
db := NewDB(bdb)
|
||||
|
||||
var existingAddr *object.Address
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
obj := generateObject(b, testPrm{})
|
||||
|
||||
existingAddr = obj.Address()
|
||||
|
||||
require.NoError(b, db.Put(obj))
|
||||
}
|
||||
|
||||
b.Run("existing address", func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := db.Get(existingAddr)
|
||||
|
||||
b.StopTimer()
|
||||
require.NoError(b, err)
|
||||
b.StartTimer()
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("non-existing address", func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
addr := object.NewAddress()
|
||||
addr.SetContainerID(testCID())
|
||||
addr.SetObjectID(testOID())
|
||||
b.StartTimer()
|
||||
|
||||
_, err := db.Get(addr)
|
||||
|
||||
b.StopTimer()
|
||||
require.Error(b, err)
|
||||
b.StartTimer()
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue