MCPcopy Create free account
hub / github.com/CPChain/chain / makeChainForBench

Function makeChainForBench

core/bench_test.go:215–236  ·  view source on GitHub ↗

makeChainForBench writes a given number of headers or empty blocks/receipts into a database.

(db database.Database, full bool, count uint64)

Source from the content-addressed store, hash-verified

213// makeChainForBench writes a given number of headers or empty blocks/receipts
214// into a database.
215func makeChainForBench(db database.Database, full bool, count uint64) {
216 var hash common.Hash
217 for n := uint64(0); n < count; n++ {
218 header := &types.Header{
219 Coinbase: common.Address{},
220 Number: big.NewInt(int64(n)),
221 ParentHash: hash,
222 TxsRoot: types.EmptyRootHash,
223 ReceiptsRoot: types.EmptyRootHash,
224 }
225 hash = header.Hash()
226
227 rawdb.WriteHeader(db, header)
228 rawdb.WriteCanonicalHash(db, hash, n)
229
230 if full || n == 0 {
231 block := types.NewBlockWithHeader(header)
232 rawdb.WriteBody(db, hash, n, block.Body())
233 rawdb.WriteReceipts(db, hash, n, nil)
234 }
235 }
236}
237
238func benchWriteChain(b *testing.B, full bool, count uint64) {
239 for i := 0; i < b.N; i++ {

Callers 2

benchWriteChainFunction · 0.85
benchReadChainFunction · 0.85

Calls 3

HashMethod · 0.95
WriteHeaderMethod · 0.80
BodyMethod · 0.80

Tested by

no test coverage detected