mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
core/state: added state copy benchmark
This commit is contained in:
parent
b5d6206bdc
commit
7c8d8eb5f9
1 changed files with 21 additions and 0 deletions
|
|
@ -222,3 +222,24 @@ func compareStateObjects(so0, so1 *StateObject, t *testing.T) {
|
||||||
t.Fatalf("Dirty mismatch: have %v, want %v", so0.dirty, so1.dirty)
|
t.Fatalf("Dirty mismatch: have %v, want %v", so0.dirty, so1.dirty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkFork(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
b.StopTimer()
|
||||||
|
db, _ := ethdb.NewMemDatabase()
|
||||||
|
state, _ := New(common.Hash{}, db)
|
||||||
|
b.StartTimer()
|
||||||
|
|
||||||
|
revertEvery := 5
|
||||||
|
nesting := 20
|
||||||
|
for x := 0; x < nesting; x++ {
|
||||||
|
pstate := state.Copy()
|
||||||
|
state.AddBalance(common.Address{byte(x)}, big.NewInt(10))
|
||||||
|
// at the very least get the balance of each previous object
|
||||||
|
state.GetBalance(common.Address{byte(x - 1)})
|
||||||
|
if x%revertEvery == 0 {
|
||||||
|
state.Set(pstate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue