diff --git a/core/vm/runtime/runtime_test.go b/core/vm/runtime/runtime_test.go index f2d05118ce..f8b8d8a425 100644 --- a/core/vm/runtime/runtime_test.go +++ b/core/vm/runtime/runtime_test.go @@ -316,3 +316,31 @@ func TestBlockhash(t *testing.T) { 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) + } +}