github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/evm/handler/handler_benchmark_test.go (about)

     1  package handler_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  
     8  	"github.com/onflow/flow-go/fvm/evm/testutils"
     9  	"github.com/onflow/flow-go/fvm/evm/types"
    10  	"github.com/onflow/flow-go/model/flow"
    11  )
    12  
    13  func BenchmarkStorage(b *testing.B) { benchmarkStorageGrowth(b, 100, 100) }
    14  
    15  // benchmark
    16  func benchmarkStorageGrowth(b *testing.B, accountCount, setupKittyCount int) {
    17  	testutils.RunWithTestBackend(b, func(backend *testutils.TestBackend) {
    18  		testutils.RunWithTestFlowEVMRootAddress(b, backend, func(rootAddr flow.Address) {
    19  			testutils.RunWithDeployedContract(b,
    20  				testutils.GetDummyKittyTestContract(b),
    21  				backend,
    22  				rootAddr,
    23  				func(tc *testutils.TestContract) {
    24  					handler := SetupHandler(b, backend, rootAddr)
    25  					accounts := make([]types.Account, accountCount)
    26  					// setup several of accounts
    27  					// note that trie growth is the function of number of accounts
    28  					for i := 0; i < accountCount; i++ {
    29  						account := handler.AccountByAddress(handler.DeployCOA(uint64(i+1)), true)
    30  						account.Deposit(types.NewFlowTokenVault(types.NewBalanceFromUFix64(100)))
    31  						accounts[i] = account
    32  					}
    33  					backend.DropEvents()
    34  					// mint kitties
    35  					for i := 0; i < setupKittyCount; i++ {
    36  						account := accounts[i%accountCount]
    37  						matronId := testutils.RandomBigInt(1000)
    38  						sireId := testutils.RandomBigInt(1000)
    39  						generation := testutils.RandomBigInt(1000)
    40  						genes := testutils.RandomBigInt(1000)
    41  						require.NotNil(b, account)
    42  						account.Call(
    43  							tc.DeployedAt,
    44  							tc.MakeCallData(b,
    45  								"CreateKitty",
    46  								matronId,
    47  								sireId,
    48  								generation,
    49  								genes,
    50  							),
    51  							300_000_000,
    52  							types.NewBalanceFromUFix64(0),
    53  						)
    54  						require.Equal(b, 2, len(backend.Events()))
    55  						backend.DropEvents() // this would make things lighter
    56  						backend.ResetStats() // reset stats
    57  					}
    58  
    59  					accounts[0].Call(
    60  						tc.DeployedAt,
    61  						tc.MakeCallData(b,
    62  							"CreateKitty",
    63  							testutils.RandomBigInt(1000),
    64  							testutils.RandomBigInt(1000),
    65  							testutils.RandomBigInt(1000),
    66  							testutils.RandomBigInt(1000),
    67  						),
    68  						300_000_000,
    69  						types.NewBalanceFromUFix64(0),
    70  					)
    71  
    72  					b.ReportMetric(float64(backend.TotalBytesRead()), "bytes_read")
    73  					b.ReportMetric(float64(backend.TotalBytesWritten()), "bytes_written")
    74  					b.ReportMetric(float64(backend.TotalStorageSize()), "total_storage_size")
    75  				})
    76  		})
    77  	})
    78  }