diff --git a/storage/operation/approvals_test.go b/storage/operation/approvals_test.go new file mode 100644 index 00000000000..38ff89d15db --- /dev/null +++ b/storage/operation/approvals_test.go @@ -0,0 +1,44 @@ +package operation_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/onflow/flow-go/model/flow" + "github.com/onflow/flow-go/storage" + "github.com/onflow/flow-go/storage/operation" + "github.com/onflow/flow-go/storage/operation/dbtest" + "github.com/onflow/flow-go/utils/unittest" +) + +func BenchmarkRetrieveApprovals(b *testing.B) { + dbtest.BenchWithDB(b, func(b *testing.B, db storage.DB) { + b.Run("RetrieveApprovals", func(b *testing.B) { + approval := unittest.ResultApprovalFixture() + require.NoError(b, db.WithReaderBatchWriter(storage.OnlyWriter(operation.InsertResultApproval(approval)))) + + b.ResetTimer() + + approvalID := approval.ID() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + var stored flow.ResultApproval + require.NoError(b, operation.RetrieveResultApproval(approvalID, &stored)(db.Reader())) + } + }) + + }) + }) +} + +func BenchmarkInsertApproval(b *testing.B) { + dbtest.BenchWithDB(b, func(b *testing.B, db storage.DB) { + b.Run("InsertApprovals", func(b *testing.B) { + for i := 0; i < b.N; i++ { + approval := unittest.ResultApprovalFixture() + require.NoError(b, db.WithReaderBatchWriter(storage.OnlyWriter(operation.InsertResultApproval(approval)))) + } + }) + }) +} diff --git a/storage/operation/dbtest/helper.go b/storage/operation/dbtest/helper.go index 67d1f5b3c64..897cdf8569d 100644 --- a/storage/operation/dbtest/helper.go +++ b/storage/operation/dbtest/helper.go @@ -72,3 +72,17 @@ func RunWithDB(t *testing.T, fn func(t *testing.T, store storage.DB)) { }) }) } + +func BenchWithDB(b *testing.B, fn func(*testing.B, storage.DB)) { + b.Run("BadgerStorage", func(b *testing.B) { + unittest.RunWithBadgerDB(b, func(db *badger.DB) { + fn(b, badgerimpl.ToDB(db)) + }) + }) + + b.Run("PebbleStorage", func(b *testing.B) { + unittest.RunWithPebbleDB(b, func(db *pebble.DB) { + fn(b, pebbleimpl.ToDB(db)) + }) + }) +}