Skip to content

Commit 53d68fe

Browse files
shekhirinholiman
andauthored
tests: report mgas/s metric in evm benchmarks (ethereum#25700)
* test(state): report mgas/s metric in EVM benchmark * revert testdata submodule update * aggregate mgas/s results * calculate elapsed time better * tests: benchmarks - handle access list + take refund into account Co-authored-by: Martin Holst Swende <martin@swende.se>
1 parent 1743e61 commit 53d68fe

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

tests/state_test.go

+29-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"reflect"
2727
"strings"
2828
"testing"
29+
"time"
2930

3031
"github.com/ethereum/go-ethereum/core"
3132
"github.com/ethereum/go-ethereum/core/rawdb"
@@ -184,12 +185,14 @@ func runBenchmark(b *testing.B, t *StateTest) {
184185
b.Error(err)
185186
return
186187
}
188+
var rules = config.Rules(new(big.Int), false)
189+
187190
vmconfig.ExtraEips = eips
188191
block := t.genesis(config).ToBlock()
189192
_, statedb := MakePreState(rawdb.NewMemoryDatabase(), t.json.Pre, false)
190193

191194
var baseFee *big.Int
192-
if config.IsLondon(new(big.Int)) {
195+
if rules.IsLondon {
193196
baseFee = t.json.Env.BaseFee
194197
if baseFee == nil {
195198
// Retesteth uses `0x10` for genesis baseFee. Therefore, it defaults to
@@ -230,17 +233,40 @@ func runBenchmark(b *testing.B, t *StateTest) {
230233
sender := vm.NewContract(vm.AccountRef(msg.From()), vm.AccountRef(msg.From()),
231234
nil, 0)
232235

236+
var (
237+
gasUsed uint64
238+
elapsed uint64
239+
refund uint64
240+
)
233241
b.ResetTimer()
234242
for n := 0; n < b.N; n++ {
235-
// Execute the message.
236243
snapshot := statedb.Snapshot()
237-
_, _, err = evm.Call(sender, *msg.To(), msg.Data(), msg.Gas(), msg.Value())
244+
if rules.IsBerlin {
245+
statedb.PrepareAccessList(msg.From(), msg.To(), vm.ActivePrecompiles(rules), msg.AccessList())
246+
}
247+
b.StartTimer()
248+
start := time.Now()
249+
250+
// Execute the message.
251+
_, leftOverGas, err := evm.Call(sender, *msg.To(), msg.Data(), msg.Gas(), msg.Value())
238252
if err != nil {
239253
b.Error(err)
240254
return
241255
}
256+
257+
b.StopTimer()
258+
elapsed += uint64(time.Since(start))
259+
refund += statedb.GetRefund()
260+
gasUsed += msg.Gas() - leftOverGas
261+
242262
statedb.RevertToSnapshot(snapshot)
243263
}
264+
if elapsed < 1 {
265+
elapsed = 1
266+
}
267+
// Keep it as uint64, multiply 100 to get two digit float later
268+
mgasps := (100 * 1000 * (gasUsed - refund)) / elapsed
269+
b.ReportMetric(float64(mgasps)/100, "mgas/s")
244270
})
245271
}
246272
}

0 commit comments

Comments
 (0)