-
Notifications
You must be signed in to change notification settings - Fork 20k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/evm: benchmarking via statetest
command + filter by name, index and fork
#30442
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked to see if there was any noticeable slowdown.
Master:
$ time yes ~/go/src/github.com/holiman/goevmlab/examples/sstore_static/sstore_test.json | head -n 1000 | go run ./cmd/evm/ statetest 2>/dev/null 1>/dev/null
real 0m3.389s
user 0m3.688s
sys 0m1.008s
This PR
$ time yes ~/go/src/github.com/holiman/goevmlab/examples/sstore_static/sstore_test.json | head -n 1000 | go run ./cmd/evm/ statetest 2>/dev/null 1>/dev/null
real 0m3.409s
user 0m3.927s
sys 0m1.042s
So 👍
Just some minor nits, otherwise lgtm
--bench
flag support to include statetest
subcommand. introduce test name, fork, index filtering flags for state test subcommand.statetest
command + filter by name, index and fork
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
} else if len(matchingTests) != 1 { | ||
return fmt.Errorf("can only benchmark single state test case (more than one matching params)") | ||
} | ||
var gasUsed uint64 | ||
result := testing.Benchmark(func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
test := matchingTests[0] | ||
_, _, gasUsed, _ = test.test.RunNoVerify(test.st, cfg, false, rawdb.HashScheme) | ||
} | ||
}) | ||
var stats execStats | ||
// Get the average execution time from the benchmarking result. | ||
// There are other useful stats here that could be reported. | ||
stats.time = time.Duration(result.NsPerOp()) | ||
stats.allocs = result.AllocsPerOp() | ||
stats.bytesAllocated = result.AllocedBytesPerOp() | ||
fmt.Fprintf(os.Stderr, `EVM gas used: %d | ||
execution time: %v | ||
allocations: %d | ||
allocated bytes: %d | ||
`, gasUsed, stats.time, stats.allocs, stats.bytesAllocated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this into its own function and do something like this
if bench {
runBenchmark()
}
return nil
which makes it a big cleaner imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one tiny nitpick that you could ignore if you want
When
evm statetest --bench
is specified, benchmark the execution similarly toevm run
. It will explicitly error if there is more than one matched subtest to be executed (newstatetest
flags are added to filter which tests are ran).Breaks the state test runner API. But I figure that we are the only consumers of this API, so it's not a big problem?