mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
Merge 5d82d92aff
into c5e44a0435
This commit is contained in:
commit
948d751ac9
5 changed files with 33 additions and 3 deletions
|
@ -45,17 +45,34 @@ struct TestBlockAndIndex {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
static void BlockToJsonVerbose(benchmark::Bench& bench)
|
static void BlockToJson(benchmark::Bench& bench, TxVerbosity verbosity)
|
||||||
{
|
{
|
||||||
TestBlockAndIndex data;
|
TestBlockAndIndex data;
|
||||||
const uint256 pow_limit{data.testing_setup->m_node.chainman->GetParams().GetConsensus().powLimit};
|
const uint256 pow_limit{data.testing_setup->m_node.chainman->GetParams().GetConsensus().powLimit};
|
||||||
bench.run([&] {
|
bench.run([&] {
|
||||||
auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, data.blockindex, data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT, pow_limit);
|
auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, data.blockindex, data.blockindex, verbosity, pow_limit);
|
||||||
ankerl::nanobench::doNotOptimizeAway(univalue);
|
ankerl::nanobench::doNotOptimizeAway(univalue);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
BENCHMARK(BlockToJsonVerbose, benchmark::PriorityLevel::HIGH);
|
static void BlockToJsonVerbosity1(benchmark::Bench& bench)
|
||||||
|
{
|
||||||
|
BlockToJson(bench, TxVerbosity::SHOW_TXID);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void BlockToJsonVerbosity2(benchmark::Bench& bench)
|
||||||
|
{
|
||||||
|
BlockToJson(bench, TxVerbosity::SHOW_DETAILS);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void BlockToJsonVerbosity3(benchmark::Bench& bench)
|
||||||
|
{
|
||||||
|
BlockToJson(bench, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(BlockToJsonVerbosity1, benchmark::PriorityLevel::HIGH);
|
||||||
|
BENCHMARK(BlockToJsonVerbosity2, benchmark::PriorityLevel::HIGH);
|
||||||
|
BENCHMARK(BlockToJsonVerbosity3, benchmark::PriorityLevel::HIGH);
|
||||||
|
|
||||||
static void BlockToJsonVerboseWrite(benchmark::Bench& bench)
|
static void BlockToJsonVerboseWrite(benchmark::Bench& bench)
|
||||||
{
|
{
|
||||||
|
|
|
@ -181,6 +181,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
|
||||||
entry.pushKV("locktime", (int64_t)tx.nLockTime);
|
entry.pushKV("locktime", (int64_t)tx.nLockTime);
|
||||||
|
|
||||||
UniValue vin{UniValue::VARR};
|
UniValue vin{UniValue::VARR};
|
||||||
|
vin.reserve(tx.vin.size());
|
||||||
|
|
||||||
// If available, use Undo data to calculate the fee. Note that txundo == nullptr
|
// If available, use Undo data to calculate the fee. Note that txundo == nullptr
|
||||||
// for coinbase transactions and for transactions where undo data is unavailable.
|
// for coinbase transactions and for transactions where undo data is unavailable.
|
||||||
|
@ -203,6 +204,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
|
||||||
}
|
}
|
||||||
if (!tx.vin[i].scriptWitness.IsNull()) {
|
if (!tx.vin[i].scriptWitness.IsNull()) {
|
||||||
UniValue txinwitness(UniValue::VARR);
|
UniValue txinwitness(UniValue::VARR);
|
||||||
|
txinwitness.reserve(tx.vin[i].scriptWitness.stack.size());
|
||||||
for (const auto& item : tx.vin[i].scriptWitness.stack) {
|
for (const auto& item : tx.vin[i].scriptWitness.stack) {
|
||||||
txinwitness.push_back(HexStr(item));
|
txinwitness.push_back(HexStr(item));
|
||||||
}
|
}
|
||||||
|
@ -232,6 +234,7 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
|
||||||
entry.pushKV("vin", std::move(vin));
|
entry.pushKV("vin", std::move(vin));
|
||||||
|
|
||||||
UniValue vout(UniValue::VARR);
|
UniValue vout(UniValue::VARR);
|
||||||
|
vout.reserve(tx.vout.size());
|
||||||
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
||||||
const CTxOut& txout = tx.vout[i];
|
const CTxOut& txout = tx.vout[i];
|
||||||
|
|
||||||
|
|
|
@ -185,6 +185,7 @@ UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIn
|
||||||
result.pushKV("size", (int)::GetSerializeSize(TX_WITH_WITNESS(block)));
|
result.pushKV("size", (int)::GetSerializeSize(TX_WITH_WITNESS(block)));
|
||||||
result.pushKV("weight", (int)::GetBlockWeight(block));
|
result.pushKV("weight", (int)::GetBlockWeight(block));
|
||||||
UniValue txs(UniValue::VARR);
|
UniValue txs(UniValue::VARR);
|
||||||
|
txs.reserve(block.vtx.size());
|
||||||
|
|
||||||
switch (verbosity) {
|
switch (verbosity) {
|
||||||
case TxVerbosity::SHOW_TXID:
|
case TxVerbosity::SHOW_TXID:
|
||||||
|
|
|
@ -70,6 +70,8 @@ public:
|
||||||
|
|
||||||
size_t size() const { return values.size(); }
|
size_t size() const { return values.size(); }
|
||||||
|
|
||||||
|
void reserve(size_t new_cap);
|
||||||
|
|
||||||
void getObjMap(std::map<std::string,UniValue>& kv) const;
|
void getObjMap(std::map<std::string,UniValue>& kv) const;
|
||||||
bool checkObject(const std::map<std::string,UniValue::VType>& memberTypes) const;
|
bool checkObject(const std::map<std::string,UniValue::VType>& memberTypes) const;
|
||||||
const UniValue& operator[](const std::string& key) const;
|
const UniValue& operator[](const std::string& key) const;
|
||||||
|
|
|
@ -240,3 +240,10 @@ const UniValue& UniValue::find_value(std::string_view key) const
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UniValue::reserve(size_t new_cap)
|
||||||
|
{
|
||||||
|
values.reserve(new_cap);
|
||||||
|
if (typ == VOBJ) {
|
||||||
|
keys.reserve(new_cap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue