Changeset View
Changeset View
Standalone View
Standalone View
src/bench/ccoins_caching.cpp
Show All 10 Lines | |||||
#include <vector> | #include <vector> | ||||
// Microbenchmark for simple accesses to a CCoinsViewCache database. Note from | // Microbenchmark for simple accesses to a CCoinsViewCache database. Note from | ||||
// laanwj, "replicating the actual usage patterns of the client is hard though, | // laanwj, "replicating the actual usage patterns of the client is hard though, | ||||
// many times micro-benchmarks of the database showed completely different | // many times micro-benchmarks of the database showed completely different | ||||
// characteristics than e.g. reindex timings. But that's not a requirement of | // characteristics than e.g. reindex timings. But that's not a requirement of | ||||
// every benchmark." | // every benchmark." | ||||
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484) | // (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484) | ||||
static void CCoinsCaching(benchmark::State &state) { | static void CCoinsCaching(benchmark::Bench &bench) { | ||||
const ECCVerifyHandle verify_handle; | const ECCVerifyHandle verify_handle; | ||||
ECC_Start(); | ECC_Start(); | ||||
FillableSigningProvider keystore; | FillableSigningProvider keystore; | ||||
CCoinsView coinsDummy; | CCoinsView coinsDummy; | ||||
CCoinsViewCache coins(&coinsDummy); | CCoinsViewCache coins(&coinsDummy); | ||||
std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs( | std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs( | ||||
keystore, coins, {{11 * COIN, 50 * COIN, 21 * COIN, 22 * COIN}}); | keystore, coins, {{11 * COIN, 50 * COIN, 21 * COIN, 22 * COIN}}); | ||||
CMutableTransaction t1; | CMutableTransaction t1; | ||||
t1.vin.resize(3); | t1.vin.resize(3); | ||||
t1.vin[0].prevout = COutPoint(dummyTransactions[0].GetId(), 1); | t1.vin[0].prevout = COutPoint(dummyTransactions[0].GetId(), 1); | ||||
t1.vin[0].scriptSig << std::vector<uint8_t>(65, 0); | t1.vin[0].scriptSig << std::vector<uint8_t>(65, 0); | ||||
t1.vin[1].prevout = COutPoint(dummyTransactions[1].GetId(), 0); | t1.vin[1].prevout = COutPoint(dummyTransactions[1].GetId(), 0); | ||||
t1.vin[1].scriptSig << std::vector<uint8_t>(65, 0) | t1.vin[1].scriptSig << std::vector<uint8_t>(65, 0) | ||||
<< std::vector<uint8_t>(33, 4); | << std::vector<uint8_t>(33, 4); | ||||
t1.vin[2].prevout = COutPoint(dummyTransactions[1].GetId(), 1); | t1.vin[2].prevout = COutPoint(dummyTransactions[1].GetId(), 1); | ||||
t1.vin[2].scriptSig << std::vector<uint8_t>(65, 0) | t1.vin[2].scriptSig << std::vector<uint8_t>(65, 0) | ||||
<< std::vector<uint8_t>(33, 4); | << std::vector<uint8_t>(33, 4); | ||||
t1.vout.resize(2); | t1.vout.resize(2); | ||||
t1.vout[0].nValue = 90 * COIN; | t1.vout[0].nValue = 90 * COIN; | ||||
t1.vout[0].scriptPubKey << OP_1; | t1.vout[0].scriptPubKey << OP_1; | ||||
// Benchmark. | // Benchmark. | ||||
while (state.KeepRunning()) { | bench.run([&] { | ||||
CTransaction t(t1); | CTransaction t(t1); | ||||
bool success = | bool success = | ||||
AreInputsStandard(t, coins, STANDARD_SCRIPT_VERIFY_FLAGS); | AreInputsStandard(t, coins, STANDARD_SCRIPT_VERIFY_FLAGS); | ||||
assert(success); | assert(success); | ||||
} | }); | ||||
ECC_Stop(); | ECC_Stop(); | ||||
} | } | ||||
BENCHMARK(CCoinsCaching, 170 * 1000); | BENCHMARK(CCoinsCaching); |