From b8b272c8c45ffad05abdb472f62d714555cbbeb7 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Mon, 12 Jul 2021 14:20:37 +0300 Subject: [PATCH] core/test: add benchmark for `storageFind` Signed-off-by: Evgeniy Stratonikov --- pkg/core/interop_system_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pkg/core/interop_system_test.go b/pkg/core/interop_system_test.go index 1b462baf4..c6519ef9e 100644 --- a/pkg/core/interop_system_test.go +++ b/pkg/core/interop_system_test.go @@ -258,6 +258,36 @@ func TestStorageDelete(t *testing.T) { }) } +func BenchmarkStorageFind(b *testing.B) { + v, contractState, context, chain := createVMAndContractState(b) + require.NoError(b, chain.contracts.Management.PutContractState(chain.dao, contractState)) + + const count = 100 + + items := make(map[string]state.StorageItem) + for i := 0; i < count; i++ { + items["abc"+random.String(10)] = random.Bytes(10) + } + for k, v := range items { + require.NoError(b, context.DAO.PutStorageItem(contractState.ID, []byte(k), v)) + require.NoError(b, context.DAO.PutStorageItem(contractState.ID+1, []byte(k), v)) + } + + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + b.StopTimer() + v.Estack().PushVal(istorage.FindDefault) + v.Estack().PushVal("abc") + v.Estack().PushVal(stackitem.NewInterop(&StorageContext{ID: contractState.ID})) + b.StartTimer() + err := storageFind(context) + if err != nil { + b.FailNow() + } + } +} + func TestStorageFind(t *testing.T) { v, contractState, context, chain := createVMAndContractState(t)