core/vm/runtime: benchmark for deep stacks

pull/30362/head
Martin Holst Swende 3 weeks ago
parent 97abdb3f39
commit 3e4926b875
No known key found for this signature in database
GPG Key ID: 683B438C05A5DDF0
  1. 61
      core/vm/runtime/runtime_test.go

@ -32,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/core/asm" "github.com/ethereum/go-ethereum/core/asm"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/eth/tracers"
@ -974,3 +975,63 @@ func BenchmarkTracerStepVsCallFrame(b *testing.B) {
benchmarkNonModifyingCode(10000000, code, "tracer-step-10M", stepTracer, b) benchmarkNonModifyingCode(10000000, code, "tracer-step-10M", stepTracer, b)
benchmarkNonModifyingCode(10000000, code, "tracer-call-frame-10M", callFrameTracer, b) benchmarkNonModifyingCode(10000000, code, "tracer-call-frame-10M", callFrameTracer, b)
} }
func TestManyLargeStacks(t *testing.T) {
// This piece of code will push 512 items to the stack, and then call itself
// recursively.
code := make([]byte, 10)
for i := range code {
code[i] = byte(vm.PUSH0)
}
code = append(code, []byte{
byte(vm.ADDRESS), // address to call
byte(vm.GAS),
byte(vm.CALL),
}...)
main := common.HexToAddress("0xbb")
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
statedb.SetCode(main, code)
//tracer := logger.NewJSONLogger(nil, os.Stdout)
var tracer *tracing.Hooks
_, _, err := Call(main, nil, &Config{
GasLimit: 10_000_000,
State: statedb,
EVMConfig: vm.Config{
Tracer: tracer,
}})
if err != nil {
t.Fatal("didn't expect error", err)
}
}
func BenchmarkLargeDeepStacks(b *testing.B) {
// This piece of code will push 512 items to the stack, and then call itself
// recursively.
code := make([]byte, 512)
for i := range code {
code[i] = byte(vm.PUSH0)
}
code = append(code, []byte{
byte(vm.ADDRESS), // address to call
byte(vm.GAS),
byte(vm.CALL),
}...)
benchmarkNonModifyingCode(10_000_000, code, "deep-large-stacks-10M", "", b)
}
func BenchmarkShortDeepStacks(b *testing.B) {
// This piece of code will push a few items to the stack, and then call itself
// recursively.
code := make([]byte, 8)
for i := range code {
code[i] = byte(vm.PUSH0)
}
code = append(code, []byte{
byte(vm.ADDRESS), // address to call
byte(vm.GAS),
byte(vm.CALL),
}...)
benchmarkNonModifyingCode(10_000_000, code, "deep-short-stacks-10M", "", b)
}

Loading…
Cancel
Save