Skip to content

Commit 42cd8c8

Browse files
committed
Add benchmarking for CreateNewBlock
1 parent eed816a commit 42cd8c8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/miner.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ void BlockAssembler::resetBlock()
139139

140140
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
141141
{
142+
int64_t nTimeStart = GetTimeMicros();
143+
142144
resetBlock();
143145

144146
pblocktemplate.reset(new CBlockTemplate());
@@ -179,6 +181,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
179181

180182
addPackageTxs();
181183

184+
int64_t nTime1 = GetTimeMicros();
185+
182186
nLastBlockTx = nBlockTx;
183187
nLastBlockSize = nBlockSize;
184188
nLastBlockWeight = nBlockWeight;
@@ -209,6 +213,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
209213
if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, false)) {
210214
throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, FormatStateMessage(state)));
211215
}
216+
int64_t nTime2 = GetTimeMicros();
217+
218+
LogPrint("bench", "CreateNewBlock() packages: %.2fms, validity: %.2fms (total %.2fms)\n", 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart));
212219

213220
return std::move(pblocktemplate);
214221
}

0 commit comments

Comments
 (0)