Changeset View
Changeset View
Standalone View
Standalone View
src/test/cuckoocache_tests.cpp
Show First 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | template <typename Cache> static void test_cache_erase(size_t megabytes) { | ||||
for (uint32_t i = 0; i < (n_insert / 4); ++i) { | for (uint32_t i = 0; i < (n_insert / 4); ++i) { | ||||
set.contains(hashes[i], true); | set.contains(hashes[i], true); | ||||
} | } | ||||
/** Insert the second half */ | /** Insert the second half */ | ||||
for (uint32_t i = (n_insert / 2); i < n_insert; ++i) { | for (uint32_t i = (n_insert / 2); i < n_insert; ++i) { | ||||
set.insert(hashes_insert_copy[i]); | set.insert(hashes_insert_copy[i]); | ||||
} | } | ||||
/** elements that we marked erased but that are still there */ | /** elements that we marked as erased but are still there */ | ||||
size_t count_erased_but_contained = 0; | size_t count_erased_but_contained = 0; | ||||
/** elements that we did not erase but are older */ | /** elements that we did not erase but are older */ | ||||
size_t count_stale = 0; | size_t count_stale = 0; | ||||
/** elements that were most recently inserted */ | /** elements that were most recently inserted */ | ||||
size_t count_fresh = 0; | size_t count_fresh = 0; | ||||
for (uint32_t i = 0; i < (n_insert / 4); ++i) { | for (uint32_t i = 0; i < (n_insert / 4); ++i) { | ||||
count_erased_but_contained += set.contains(hashes[i], false); | count_erased_but_contained += set.contains(hashes[i], false); | ||||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | template <typename Cache> static void test_cache_generations() { | ||||
// We use deterministic values, but this test has also passed on many | // We use deterministic values, but this test has also passed on many | ||||
// iterations with non-deterministic values, so it isn't "overfit" to the | // iterations with non-deterministic values, so it isn't "overfit" to the | ||||
// specific entropy in FastRandomContext(true) and implementation of the | // specific entropy in FastRandomContext(true) and implementation of the | ||||
// cache. | // cache. | ||||
SeedInsecureRand(true); | SeedInsecureRand(true); | ||||
// block_activity models a chunk of network activity. n_insert elements are | // block_activity models a chunk of network activity. n_insert elements are | ||||
// adde to the cache. The first and last n/4 are stored for removal later | // added to the cache. The first and last n/4 are stored for removal later | ||||
// and the middle n/2 are not stored. This models a network which uses half | // and the middle n/2 are not stored. This models a network which uses half | ||||
// the signatures of recently (since the last block) added transactions | // the signatures of recently (since the last block) added transactions | ||||
// immediately and never uses the other half. | // immediately and never uses the other half. | ||||
struct block_activity { | struct block_activity { | ||||
std::vector<uint256> reads; | std::vector<uint256> reads; | ||||
block_activity(uint32_t n_insert, Cache &c) : reads() { | block_activity(uint32_t n_insert, Cache &c) : reads() { | ||||
std::vector<uint256> inserts; | std::vector<uint256> inserts; | ||||
inserts.resize(n_insert); | inserts.resize(n_insert); | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |