@@ -26,6 +26,7 @@ import (
26
26
"reflect"
27
27
"strings"
28
28
"testing"
29
+ "time"
29
30
30
31
"github.com/ethereum/go-ethereum/core"
31
32
"github.com/ethereum/go-ethereum/core/rawdb"
@@ -184,12 +185,14 @@ func runBenchmark(b *testing.B, t *StateTest) {
184
185
b .Error (err )
185
186
return
186
187
}
188
+ var rules = config .Rules (new (big.Int ), false )
189
+
187
190
vmconfig .ExtraEips = eips
188
191
block := t .genesis (config ).ToBlock ()
189
192
_ , statedb := MakePreState (rawdb .NewMemoryDatabase (), t .json .Pre , false )
190
193
191
194
var baseFee * big.Int
192
- if config .IsLondon ( new (big. Int )) {
195
+ if rules .IsLondon {
193
196
baseFee = t .json .Env .BaseFee
194
197
if baseFee == nil {
195
198
// Retesteth uses `0x10` for genesis baseFee. Therefore, it defaults to
@@ -230,17 +233,40 @@ func runBenchmark(b *testing.B, t *StateTest) {
230
233
sender := vm .NewContract (vm .AccountRef (msg .From ()), vm .AccountRef (msg .From ()),
231
234
nil , 0 )
232
235
236
+ var (
237
+ gasUsed uint64
238
+ elapsed uint64
239
+ refund uint64
240
+ )
233
241
b .ResetTimer ()
234
242
for n := 0 ; n < b .N ; n ++ {
235
- // Execute the message.
236
243
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 ())
238
252
if err != nil {
239
253
b .Error (err )
240
254
return
241
255
}
256
+
257
+ b .StopTimer ()
258
+ elapsed += uint64 (time .Since (start ))
259
+ refund += statedb .GetRefund ()
260
+ gasUsed += msg .Gas () - leftOverGas
261
+
242
262
statedb .RevertToSnapshot (snapshot )
243
263
}
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" )
244
270
})
245
271
}
246
272
}
0 commit comments