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

Function benchInsertChain

core/bench_test.go:131–169  ·  view source on GitHub ↗
(b *testing.B, disk bool, gen func(int, *BlockGen))

Source from the content-addressed store, hash-verified

129}
130
131func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
132 // Create the database in memory or in a temporary directory.
133 var db database.Database
134 if !disk {
135 db = database.NewMemDatabase()
136 } else {
137 dir, err := ioutil.TempDir("", "eth-core-bench")
138 if err != nil {
139 b.Fatalf("cannot create temporary directory: %v", err)
140 }
141 defer os.RemoveAll(dir)
142 db, err = database.NewLDBDatabase(dir, 128, 128)
143 if err != nil {
144 b.Fatalf("cannot create temporary database: %v", err)
145 }
146 defer db.Close()
147 }
148
149 // Generate a chain of b.N blocks using the supplied block
150 // generator function.
151 gspec := Genesis{
152 Config: configs.TestChainConfig,
153 Alloc: GenesisAlloc{benchRootAddr: {Balance: benchRootFunds}},
154 }
155 genesis := gspec.MustCommit(db)
156
157 remoteDB := database.NewIpfsDbWithAdapter(database.NewFakeIpfsAdapter())
158 chain, _ := GenerateChain(gspec.Config, genesis, dpor.NewFaker(configs.ChainConfigInfo().Dpor, db), db, remoteDB, b.N, gen)
159
160 // Time the insertion of the new chain.
161 // State and blocks are stored in the same DB.
162 chainman, _ := NewBlockChain(db, nil, gspec.Config, dpor.NewFaker(configs.ChainConfigInfo().Dpor, db), vm.Config{}, remoteDB, nil)
163 defer chainman.Stop()
164 b.ReportAllocs()
165 b.ResetTimer()
166 if i, err := chainman.InsertChain(chain); err != nil {
167 b.Fatalf("insert error (block %d): %v\n", i, err)
168 }
169}
170
171// func BenchmarkChainRead_header_10k(b *testing.B) {
172// benchReadChain(b, false, 10000)

Calls 7

CloseMethod · 0.95
MustCommitMethod · 0.95
StopMethod · 0.95
InsertChainMethod · 0.95
GenerateChainFunction · 0.85
NewBlockChainFunction · 0.85
ChainConfigInfoMethod · 0.80

Tested by

no test coverage detected