101 lines
1.7 KiB
Go
101 lines
1.7 KiB
Go
|
package meta
|
||
|
|
||
|
import (
|
||
|
"crypto/rand"
|
||
|
"os"
|
||
|
"testing"
|
||
|
|
||
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
"go.etcd.io/bbolt"
|
||
|
)
|
||
|
|
||
|
func addNFilters(fs *objectSDK.SearchFilters, n int) {
|
||
|
for i := 0; i < n; i++ {
|
||
|
key := make([]byte, 32)
|
||
|
rand.Read(key)
|
||
|
|
||
|
val := make([]byte, 32)
|
||
|
rand.Read(val)
|
||
|
|
||
|
fs.AddFilter(string(key), string(val), objectSDK.MatchStringEqual)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func BenchmarkDB_Select(b *testing.B) {
|
||
|
path := "select_test.db"
|
||
|
|
||
|
bdb, err := bbolt.Open(path, 0600, nil)
|
||
|
require.NoError(b, err)
|
||
|
|
||
|
defer func() {
|
||
|
bdb.Close()
|
||
|
os.Remove(path)
|
||
|
}()
|
||
|
|
||
|
db := NewDB(bdb)
|
||
|
|
||
|
for i := 0; i < 100; i++ {
|
||
|
obj := generateObject(b, testPrm{
|
||
|
withParent: true,
|
||
|
attrNum: 100,
|
||
|
})
|
||
|
|
||
|
require.NoError(b, db.Put(obj))
|
||
|
}
|
||
|
|
||
|
for _, item := range []struct {
|
||
|
name string
|
||
|
filters func(*objectSDK.SearchFilters)
|
||
|
}{
|
||
|
{
|
||
|
name: "empty",
|
||
|
filters: func(*objectSDK.SearchFilters) {
|
||
|
return
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
name: "1 filter",
|
||
|
filters: func(fs *objectSDK.SearchFilters) {
|
||
|
addNFilters(fs, 1)
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
name: "10 filters",
|
||
|
filters: func(fs *objectSDK.SearchFilters) {
|
||
|
addNFilters(fs, 10)
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
name: "100 filters",
|
||
|
filters: func(fs *objectSDK.SearchFilters) {
|
||
|
addNFilters(fs, 100)
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
name: "1000 filters",
|
||
|
filters: func(fs *objectSDK.SearchFilters) {
|
||
|
addNFilters(fs, 1000)
|
||
|
},
|
||
|
},
|
||
|
} {
|
||
|
b.Run(item.name, func(b *testing.B) {
|
||
|
b.ReportAllocs()
|
||
|
b.ResetTimer()
|
||
|
|
||
|
for i := 0; i < b.N; i++ {
|
||
|
b.StopTimer()
|
||
|
fs := new(objectSDK.SearchFilters)
|
||
|
item.filters(fs)
|
||
|
b.StartTimer()
|
||
|
|
||
|
_, err := db.Select(*fs)
|
||
|
|
||
|
b.StopTimer()
|
||
|
require.NoError(b, err)
|
||
|
b.StartTimer()
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|