diff options
Diffstat (limited to 'tests/state_test_util.go')
-rw-r--r-- | tests/state_test_util.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 7086de389..695e50852 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -23,6 +23,7 @@ import ( "io" "math/big" "strconv" + "testing" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" @@ -60,6 +61,61 @@ func RunStateTest(p string, skipTests []string) error { } +func BenchStateTest(p string, conf bconf, b *testing.B) error { + tests := make(map[string]VmTest) + if err := readJsonFile(p, &tests); err != nil { + return err + } + test, ok := tests[conf.name] + if !ok { + return fmt.Errorf("test not found: %s", conf.name) + } + + pNoJit := vm.DisableJit + vm.DisableJit = conf.nojit + pForceJit := vm.ForceJit + vm.ForceJit = conf.precomp + + // XXX Yeah, yeah... + env := make(map[string]string) + env["currentCoinbase"] = test.Env.CurrentCoinbase + env["currentDifficulty"] = test.Env.CurrentDifficulty + env["currentGasLimit"] = test.Env.CurrentGasLimit + env["currentNumber"] = test.Env.CurrentNumber + env["previousHash"] = test.Env.PreviousHash + if n, ok := test.Env.CurrentTimestamp.(float64); ok { + env["currentTimestamp"] = strconv.Itoa(int(n)) + } else { + env["currentTimestamp"] = test.Env.CurrentTimestamp.(string) + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + benchStateTest(test, env, b) + } + + vm.DisableJit = pNoJit + vm.ForceJit = pForceJit + + return nil +} + +func benchStateTest(test VmTest, env map[string]string, b *testing.B) { + b.StopTimer() + db, _ := ethdb.NewMemDatabase() + statedb := state.New(common.Hash{}, db) + for addr, account := range test.Pre { + obj := StateObjectFromAccount(db, addr, account) + statedb.SetStateObject(obj) + for a, v := range account.Storage { + obj.SetState(common.HexToHash(a), common.HexToHash(v)) + } + } + b.StartTimer() + + RunState(statedb, env, test.Exec) +} + func runStateTests(tests map[string]VmTest, skipTests []string) error { skipTest := make(map[string]bool, len(skipTests)) for _, name := range skipTests { |