github.com/ledgerwatch/erigon-lib@v1.0.0/commitment/hex_patricia_hashed_bench_test.go (about) 1 package commitment 2 3 import ( 4 "encoding/hex" 5 "math/rand" 6 "testing" 7 8 "github.com/ledgerwatch/erigon-lib/common/length" 9 ) 10 11 func Benchmark_HexPatriciaHahsed_ReviewKeys(b *testing.B) { 12 ms := NewMockState(&testing.T{}) 13 hph := NewHexPatriciaHashed(length.Addr, ms.branchFn, ms.accountFn, ms.storageFn) 14 hph.SetTrace(false) 15 16 builder := NewUpdateBuilder() 17 18 rnd := rand.New(rand.NewSource(133777)) 19 keysCount := rnd.Int31n(10_000_0) 20 21 // generate updates 22 for i := int32(0); i < keysCount; i++ { 23 key := make([]byte, length.Addr) 24 25 for j := 0; j < len(key); j++ { 26 key[j] = byte(rnd.Intn(256)) 27 } 28 builder.Balance(hex.EncodeToString(key), rnd.Uint64()) 29 } 30 31 pk, hk, _ := builder.Build() 32 33 b.Run("review_keys", func(b *testing.B) { 34 for i, j := 0, 0; i < b.N; i, j = i+1, j+1 { 35 if j >= len(pk) { 36 j = 0 37 } 38 39 hph.ReviewKeys(pk[j:j+1], hk[j:j+1]) 40 } 41 }) 42 }