core/vm: reduce overhead in instructions-benchmark (#24860)
* core/vm: reduce footprint of OP benchmark * core/vm: for opBenchmark, add code to detect inputs mutation * Update core/vm/instructions_test.go Co-authored-by: Martin Holst Swende <martin@swende.se> * core/vm: opBenchmark, stop timer before sanity-test code Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
parent
af806168b6
commit
fe5a26733c
@ -284,26 +284,33 @@ func opBenchmark(bench *testing.B, op executionFunc, args ...string) {
|
|||||||
var (
|
var (
|
||||||
env = NewEVM(BlockContext{}, TxContext{}, nil, params.TestChainConfig, Config{})
|
env = NewEVM(BlockContext{}, TxContext{}, nil, params.TestChainConfig, Config{})
|
||||||
stack = newstack()
|
stack = newstack()
|
||||||
|
scope = &ScopeContext{nil, stack, nil}
|
||||||
evmInterpreter = NewEVMInterpreter(env, env.Config)
|
evmInterpreter = NewEVMInterpreter(env, env.Config)
|
||||||
)
|
)
|
||||||
|
|
||||||
env.interpreter = evmInterpreter
|
env.interpreter = evmInterpreter
|
||||||
// convert args
|
// convert args
|
||||||
byteArgs := make([][]byte, len(args))
|
intArgs := make([]*uint256.Int, len(args))
|
||||||
for i, arg := range args {
|
for i, arg := range args {
|
||||||
byteArgs[i] = common.Hex2Bytes(arg)
|
intArgs[i] = new(uint256.Int).SetBytes(common.Hex2Bytes(arg))
|
||||||
}
|
}
|
||||||
pc := uint64(0)
|
pc := uint64(0)
|
||||||
bench.ResetTimer()
|
bench.ResetTimer()
|
||||||
for i := 0; i < bench.N; i++ {
|
for i := 0; i < bench.N; i++ {
|
||||||
for _, arg := range byteArgs {
|
for _, arg := range intArgs {
|
||||||
a := new(uint256.Int)
|
stack.push(arg)
|
||||||
a.SetBytes(arg)
|
|
||||||
stack.push(a)
|
|
||||||
}
|
}
|
||||||
op(&pc, evmInterpreter, &ScopeContext{nil, stack, nil})
|
op(&pc, evmInterpreter, scope)
|
||||||
stack.pop()
|
stack.pop()
|
||||||
}
|
}
|
||||||
|
bench.StopTimer()
|
||||||
|
|
||||||
|
for i, arg := range args {
|
||||||
|
want := new(uint256.Int).SetBytes(common.Hex2Bytes(arg))
|
||||||
|
if have := intArgs[i]; !want.Eq(have) {
|
||||||
|
bench.Fatalf("input #%d mutated, have %x want %x", i, have, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkOpAdd64(b *testing.B) {
|
func BenchmarkOpAdd64(b *testing.B) {
|
||||||
|
Loading…
Reference in New Issue
Block a user