This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: add benchmarks to core components
Fixes #480
- Loading branch information
Showing
5 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package app | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/simapp" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
"github.com/tendermint/tendermint/libs/log" | ||
dbm "github.com/tendermint/tm-db" | ||
"github.com/tharsis/ethermint/encoding" | ||
) | ||
|
||
func BenchmarkEthermintApp_ExportAppStateAndValidators(b *testing.B) { | ||
db := dbm.NewMemDB() | ||
app := NewEthermintApp(log.NewTMLogger(io.Discard), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encoding.MakeConfig(ModuleBasics), simapp.EmptyAppOptions{}) | ||
|
||
genesisState := NewDefaultGenesisState() | ||
stateBytes, err := json.MarshalIndent(genesisState, "", " ") | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
|
||
// Initialize the chain | ||
app.InitChain( | ||
abci.RequestInitChain{ | ||
ChainId: "ethermint_9000-1", | ||
Validators: []abci.ValidatorUpdate{}, | ||
AppStateBytes: stateBytes, | ||
}, | ||
) | ||
app.Commit() | ||
|
||
b.ResetTimer() | ||
b.ReportAllocs() | ||
for i := 0; i < b.N; i++ { | ||
// Making a new app object with the db, so that initchain hasn't been called | ||
app2 := NewEthermintApp(log.NewTMLogger(log.NewSyncWriter(io.Discard)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encoding.MakeConfig(ModuleBasics), simapp.EmptyAppOptions{}) | ||
if _, err := app2.ExportAppStateAndValidators(false, []string{}); err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ethsecp256k1 | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func BenchmarkGenerateKey(b *testing.B) { | ||
b.ReportAllocs() | ||
for i := 0; i < b.N; i++ { | ||
if _, err := GenerateKey(); err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkPubKey_VerifySignature(b *testing.B) { | ||
privKey, err := GenerateKey() | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
pubKey := privKey.PubKey() | ||
|
||
b.ResetTimer() | ||
b.ReportAllocs() | ||
for i := 0; i < b.N; i++ { | ||
msg := []byte(fmt.Sprintf("%10d", i)) | ||
sig, err := privKey.Sign(msg) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
pubKey.VerifySignature(msg, sig) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package hd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
ethermint "github.com/tharsis/ethermint/types" | ||
) | ||
|
||
func BenchmarkEthSecp256k1Algo_Derive(b *testing.B) { | ||
b.ReportAllocs() | ||
for i := 0; i < b.N; i++ { | ||
deriveFn := EthSecp256k1.Derive() | ||
if _, err := deriveFn(mnemonic, keyring.DefaultBIP39Passphrase, ethermint.BIP44HDPath); err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkEthSecp256k1Algo_Generate(b *testing.B) { | ||
bz, err := EthSecp256k1.Derive()(mnemonic, keyring.DefaultBIP39Passphrase, ethermint.BIP44HDPath) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
|
||
b.ResetTimer() | ||
b.ReportAllocs() | ||
for i := 0; i < b.N; i++ { | ||
(ðSecp256k1Algo{}).Generate()(bz) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func BenchmarkParseChainID(b *testing.B) { | ||
b.ReportAllocs() | ||
// Start at 1, for valid EIP155, see regexEIP155 variable. | ||
for i := 1; i < b.N; i++ { | ||
chainID := fmt.Sprintf("ethermint_1-%d", i) | ||
if _, err := ParseChainID(chainID); err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} |