Skip to content
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

tests: report mgas/s metric in evm benchmarks #25700

Merged
merged 5 commits into from
Sep 28, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions tests/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"reflect"
"strings"
"testing"
"time"

"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
Expand Down Expand Up @@ -238,17 +239,36 @@ func runBenchmark(b *testing.B, t *StateTest) {
sender := vm.NewContract(vm.AccountRef(msg.From()), vm.AccountRef(msg.From()),
nil, 0)

var gasUsed uint64
var elapsed uint64

b.ResetTimer()
for n := 0; n < b.N; n++ {
// Execute the message.
snapshot := statedb.Snapshot()
_, _, err = evm.Call(sender, *msg.To(), msg.Data(), msg.Gas(), msg.Value())

b.StartTimer()
start := time.Now()
Comment on lines +255 to +256
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so annoying. The b has a duration field which we cannot reach, so have to do this whole parallel timekeeping work. Would be nice to somehow get around that, but I don't know how.


// Execute the message.
_, leftOverGas, err := evm.Call(sender, *msg.To(), msg.Data(), msg.Gas(), msg.Value())
if err != nil {
b.Error(err)
return
}

b.StopTimer()
elapsed += uint64(time.Since(start))
gasUsed += msg.Gas() - leftOverGas
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not quite accurate metric. We should also take into account the refunds when calculating the mgas/s.
This error is also present in core/blockchain_insert.go,

			"elapsed", common.PrettyDuration(elapsed), "mgasps", float64(st.usedGas) * 1000 / float64(elapsed),

... but we should fix it in both places, rather than do it erroneously here too.


statedb.RevertToSnapshot(snapshot)
}

if elapsed < 1 {
elapsed = 1
}
// Keep it as uint64, multiply 100 to get two digit float later
mgasps := (100 * 1000 * gasUsed) / elapsed
Copy link
Contributor

@holiman holiman Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: could either the aggregation of gasUsed go above uint64Max, or, alternatively, 100*1000 mult here might push it over ?
If so, we would be better off keeping track of it as a big.Int.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems fine:

➜  go-ethereum git:(benchmark-evm-mgas) fd '.json' tests/evm-benchmarks/benchmarks | # Get all test file paths
xargs jq -r 'values[] | .env.currentGasLimit' | # Extract gas limit
xargs -L 1 cast --to-dec | # Hex -> dec
sort -u | # Unique 
awk '{ print 18446744073709551615 - 100 * 1000 * $0 * 30000 }' # math.MaxUint64 - 100 * 1000 * gasUsed * b.N

15446744073709551616

b.ReportMetric(float64(mgasps)/100, "mgas/s")
})
}
}