core/vm/runtime: benchmark

This commit is contained in:
Martin Holst Swende 2020-03-17 22:20:15 +01:00
parent e431a23c09
commit fa547bd18b
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -316,3 +316,31 @@ func TestBlockhash(t *testing.T) {
t.Errorf("suboptimal; too much chain iteration, expected %d, got %d", exp, got) t.Errorf("suboptimal; too much chain iteration, expected %d, got %d", exp, got)
} }
} }
// BenchmarkSimpleLoop test a pretty simple loop which loops
// 1M (1 048 575) times.
// Takes about 200 ms
func BenchmarkSimpleLoop(b *testing.B) {
// 0xfffff = 1048575 loops
code := []byte{
byte(vm.PUSH3), 0x0f, 0xff, 0xff,
byte(vm.JUMPDEST), // [ count ]
byte(vm.PUSH1), 1, // [count, 1]
byte(vm.SWAP1), // [1, count]
byte(vm.SUB), // [ count -1 ]
byte(vm.DUP1), // [ count -1 , count-1]
byte(vm.PUSH1), 4, // [count-1, count -1, label]
byte(vm.JUMPI), // [ 0 ]
byte(vm.STOP),
}
//tracer := vm.NewJSONLogger(nil, os.Stdout)
//Execute(code, nil, &Config{
// EVMConfig: vm.Config{
// Debug: true,
// Tracer: tracer,
// }})
for i := 0; i < b.N; i++ {
Execute(code, nil, nil)
}
}