diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-08-08 21:36:26 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-08-08 21:36:26 +0800 |
commit | c93f0b9f4ba84933110435a80055cdaabd078159 (patch) | |
tree | c51e0d5704aa08595ebdd7e03b61309fe69fe848 /tests/vm_test_util.go | |
parent | 312128384b1c32306123f8ad3be1be32bbd8235c (diff) | |
parent | ac697326a6045eaa760b159e4bda37c57be61cbf (diff) | |
download | dexon-c93f0b9f4ba84933110435a80055cdaabd078159.tar dexon-c93f0b9f4ba84933110435a80055cdaabd078159.tar.gz dexon-c93f0b9f4ba84933110435a80055cdaabd078159.tar.bz2 dexon-c93f0b9f4ba84933110435a80055cdaabd078159.tar.lz dexon-c93f0b9f4ba84933110435a80055cdaabd078159.tar.xz dexon-c93f0b9f4ba84933110435a80055cdaabd078159.tar.zst dexon-c93f0b9f4ba84933110435a80055cdaabd078159.zip |
Merge pull request #1490 from obscuren/jit-vm
core/vm: jit vm
Diffstat (limited to 'tests/vm_test_util.go')
-rw-r--r-- | tests/vm_test_util.go | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/tests/vm_test_util.go b/tests/vm_test_util.go index e63a92558..b29dcd20f 100644 --- a/tests/vm_test_util.go +++ b/tests/vm_test_util.go @@ -22,6 +22,7 @@ import ( "io" "math/big" "strconv" + "testing" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" @@ -48,8 +49,79 @@ func RunVmTestWithReader(r io.Reader, skipTests []string) error { return nil } -func RunVmTest(p string, skipTests []string) error { +type bconf struct { + name string + precomp bool + nojit bool +} + +func BenchVmTest(p string, conf bconf, b *testing.B) error { + tests := make(map[string]VmTest) + err := readJsonFile(p, &tests) + if 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 + + 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) + } + /* + if conf.precomp { + program := vm.NewProgram(test.code) + err := vm.AttachProgram(program) + if err != nil { + return err + } + } + */ + + b.ResetTimer() + for i := 0; i < b.N; i++ { + benchVmTest(test, env, b) + } + + vm.DisableJit = pNoJit + vm.ForceJit = pForceJit + + return nil +} + +func benchVmTest(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() + + RunVm(statedb, env, test.Exec) +} + +func RunVmTest(p string, skipTests []string) error { tests := make(map[string]VmTest) err := readJsonFile(p, &tests) if err != nil { |