Skip to content

Commit

Permalink
More Benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Mar 7, 2021
1 parent d92ab33 commit 93a20e7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 27 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca
github.com/tendermint/tendermint v0.34.8
github.com/tendermint/tm-db v0.6.4
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
github.com/CosmWasm/wasmvm v0.13.1-0.20210125204657-16df1fdaf712 h1:8gMCeYi0In+3R+ox44SfXoY9a7KXngH8sDwsg+eLwB4=
github.com/CosmWasm/wasmvm v0.13.1-0.20210125204657-16df1fdaf712/go.mod h1:Id107qllDJyJjVQQsKMOy2YYF98sqPJ2t+jX1QES40A=
github.com/CosmWasm/wasmvm v0.14.0-alpha1 h1:n6cKrufXvaAzDaUfw1wEr39hNBLv3BY2usUnShmAFwQ=
github.com/CosmWasm/wasmvm v0.14.0-alpha1/go.mod h1:Id107qllDJyJjVQQsKMOy2YYF98sqPJ2t+jX1QES40A=
github.com/CosmWasm/wasmvm v0.14.0-alpha2 h1:IF+ZNYe6XxKmAZaAzX/Y2dXB1v3l+J0+Vyz69CtojOQ=
github.com/CosmWasm/wasmvm v0.14.0-alpha2/go.mod h1:Id107qllDJyJjVQQsKMOy2YYF98sqPJ2t+jX1QES40A=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
Expand Down
64 changes: 43 additions & 21 deletions x/wasm/internal/keeper/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,53 @@ package keeper
import (
"github.com/CosmWasm/wasmd/x/wasm/internal/types"
"github.com/stretchr/testify/require"
"github.com/syndtr/goleveldb/leveldb/opt"
dbm "github.com/tendermint/tm-db"
"testing"
)

func BenchmarkExecutionWithPinnedCodesAndCosmosMemoryDB(b *testing.B) {
wasmConfig := types.WasmConfig{MemoryCacheSize: 0}
ctx, keepers := createTestInput(b, false, SupportedFeatures, nil, nil, wasmConfig)
example := InstantiateHackatomExampleContract(b, ctx, keepers)
require.NoError(b, keepers.WasmKeeper.PinCode(ctx, example.CodeID))
func BenchmarkExecution(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := keepers.WasmKeeper.QuerySmart(ctx, example.Contract, []byte(`{"verifier":{}}`))
require.NoError(b, err)
specs := map[string]struct {
pinned bool
db func() dbm.DB
}{
"unpinned, memory db": {
db: func() dbm.DB { return dbm.NewMemDB() },
},
"pinned, memory db": {
db: func() dbm.DB { return dbm.NewMemDB() },
pinned: true,
},
"unpinned, level db": {
db: func() dbm.DB {
levelDB, err := dbm.NewGoLevelDBWithOpts("testing", b.TempDir(), &opt.Options{BlockCacher: opt.NoCacher})
require.NoError(b, err)
return levelDB
},
},
"pinned, level db": {
db: func() dbm.DB {
levelDB, err := dbm.NewGoLevelDBWithOpts("testing", b.TempDir(), &opt.Options{BlockCacher: opt.NoCacher})
require.NoError(b, err)
return levelDB
},
pinned: true,
},
}
// BenchmarkExecutionWithPinnedPinCodesAndCosmosMemoryDB-8 8148 141228 ns/op
}
func BenchmarkExecutionNonePinnedAndCosmosMemoryDB(b *testing.B) {
wasmConfig := types.WasmConfig{MemoryCacheSize: 0}
ctx, keepers := createTestInput(b, false, SupportedFeatures, nil, nil, wasmConfig)
example := InstantiateHackatomExampleContract(b, ctx, keepers)

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := keepers.WasmKeeper.QuerySmart(ctx, example.Contract, []byte(`{"verifier":{}}`))
require.NoError(b, err)
for name, spec := range specs {
b.Run(name, func(b *testing.B) {
wasmConfig := types.WasmConfig{MemoryCacheSize: 0}
ctx, keepers := createTestInput(b, false, SupportedFeatures, nil, nil, wasmConfig, spec.db())
example := InstantiateHackatomExampleContract(b, ctx, keepers)
if spec.pinned {
require.NoError(b, keepers.WasmKeeper.PinCode(ctx, example.CodeID))
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := keepers.WasmKeeper.QuerySmart(ctx, example.Contract, []byte(`{"verifier":{}}`))
require.NoError(b, err)
}
})
}
//BenchmarkExecutionNonePinnedAndCosmosMemoryDB-8 320 3685224 ns/op
}
5 changes: 3 additions & 2 deletions x/wasm/internal/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ type TestingT interface {
func CreateTestInput(t TestingT, isCheckTx bool, supportedFeatures string, encoders *MessageEncoders, queriers *QueryPlugins) (sdk.Context, TestKeepers) {
// Load default wasm config
wasmConfig := types.DefaultWasmConfig()
return createTestInput(t, isCheckTx, supportedFeatures, encoders, queriers, wasmConfig)
db := dbm.NewMemDB()
return createTestInput(t, isCheckTx, supportedFeatures, encoders, queriers, wasmConfig, db)
}

// encoders can be nil to accept the defaults, or set it to override some of the message handlers (like default)
Expand All @@ -154,6 +155,7 @@ func createTestInput(
encoders *MessageEncoders,
queriers *QueryPlugins,
wasmConfig types.WasmConfig,
db dbm.DB,
) (sdk.Context, TestKeepers) {
tempDir := t.TempDir()

Expand All @@ -169,7 +171,6 @@ func createTestInput(
keyCapability := sdk.NewKVStoreKey(capabilitytypes.StoreKey)
keyCapabilityTransient := storetypes.NewMemoryStoreKey(capabilitytypes.MemStoreKey)

db := dbm.NewMemDB()
ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(keyWasm, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyAcc, sdk.StoreTypeIAVL, db)
Expand Down

0 comments on commit 93a20e7

Please sign in to comment.