Changeset View
Changeset View
Standalone View
Standalone View
src/bench/ccoins_caching.cpp
Show All 24 Lines | SetupDummyInputs(CBasicKeyStore &keystoreRet, CCoinsViewCache &coinsRet) { | ||||
CKey key[4]; | CKey key[4]; | ||||
for (int i = 0; i < 4; i++) { | for (int i = 0; i < 4; i++) { | ||||
key[i].MakeNewKey(i % 2); | key[i].MakeNewKey(i % 2); | ||||
keystoreRet.AddKey(key[i]); | keystoreRet.AddKey(key[i]); | ||||
} | } | ||||
// Create some dummy input transactions | // Create some dummy input transactions | ||||
dummyTransactions[0].vout.resize(2); | dummyTransactions[0].vout.resize(2); | ||||
dummyTransactions[0].vout[0].nValue = 11 * CENT; | dummyTransactions[0].vout[0].nValue = 11 * CENT.GetSatoshis(); | ||||
dummyTransactions[0].vout[0].scriptPubKey | dummyTransactions[0].vout[0].scriptPubKey | ||||
<< ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG; | << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG; | ||||
dummyTransactions[0].vout[1].nValue = 50 * CENT; | dummyTransactions[0].vout[1].nValue = 50 * CENT.GetSatoshis(); | ||||
dummyTransactions[0].vout[1].scriptPubKey | dummyTransactions[0].vout[1].scriptPubKey | ||||
<< ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG; | << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG; | ||||
AddCoins(coinsRet, dummyTransactions[0], 0); | AddCoins(coinsRet, dummyTransactions[0], 0); | ||||
dummyTransactions[1].vout.resize(2); | dummyTransactions[1].vout.resize(2); | ||||
dummyTransactions[1].vout[0].nValue = 21 * CENT; | dummyTransactions[1].vout[0].nValue = 21 * CENT.GetSatoshis(); | ||||
dummyTransactions[1].vout[0].scriptPubKey = | dummyTransactions[1].vout[0].scriptPubKey = | ||||
GetScriptForDestination(key[2].GetPubKey().GetID()); | GetScriptForDestination(key[2].GetPubKey().GetID()); | ||||
dummyTransactions[1].vout[1].nValue = 22 * CENT; | dummyTransactions[1].vout[1].nValue = 22 * CENT.GetSatoshis(); | ||||
dummyTransactions[1].vout[1].scriptPubKey = | dummyTransactions[1].vout[1].scriptPubKey = | ||||
GetScriptForDestination(key[3].GetPubKey().GetID()); | GetScriptForDestination(key[3].GetPubKey().GetID()); | ||||
AddCoins(coinsRet, dummyTransactions[1], 0); | AddCoins(coinsRet, dummyTransactions[1], 0); | ||||
return dummyTransactions; | return dummyTransactions; | ||||
} | } | ||||
// Microbenchmark for simple accesses to a CCoinsViewCache database. Note from | // Microbenchmark for simple accesses to a CCoinsViewCache database. Note from | ||||
Show All 18 Lines | static void CCoinsCaching(benchmark::State &state) { | ||||
t1.vin[1].prevout.n = 0; | t1.vin[1].prevout.n = 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.hash = dummyTransactions[1].GetId(); | t1.vin[2].prevout.hash = dummyTransactions[1].GetId(); | ||||
t1.vin[2].prevout.n = 1; | t1.vin[2].prevout.n = 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 * CENT; | t1.vout[0].nValue = 90 * CENT.GetSatoshis(); | ||||
t1.vout[0].scriptPubKey << OP_1; | t1.vout[0].scriptPubKey << OP_1; | ||||
// Benchmark. | // Benchmark. | ||||
while (state.KeepRunning()) { | while (state.KeepRunning()) { | ||||
bool success = AreInputsStandard(t1, coins); | bool success = AreInputsStandard(t1, coins); | ||||
assert(success); | assert(success); | ||||
CAmount value = coins.GetValueIn(t1); | CAmount value = coins.GetValueIn(t1); | ||||
assert(value == (50 + 21 + 22) * CENT); | assert(value == (50 + 21 + 22) * CENT.GetSatoshis()); | ||||
} | } | ||||
} | } | ||||
BENCHMARK(CCoinsCaching); | BENCHMARK(CCoinsCaching); |