Changeset View
Changeset View
Standalone View
Standalone View
src/test/cuckoocache_tests.cpp
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | static double test_cache(size_t megabytes, double load) { | ||||
} | } | ||||
/** | /** | ||||
* We make a copy of the hashes because future optimizations of the | * We make a copy of the hashes because future optimizations of the | ||||
* cuckoocache may overwrite the inserted element, so the test is "future | * cuckoocache may overwrite the inserted element, so the test is "future | ||||
* proofed". | * proofed". | ||||
*/ | */ | ||||
std::vector<uint256> hashes_insert_copy = hashes; | std::vector<uint256> hashes_insert_copy = hashes; | ||||
/** Do the insert */ | /** Do the insert */ | ||||
for (uint256 &h : hashes_insert_copy) { | for (const uint256 &h : hashes_insert_copy) { | ||||
set.insert(h); | set.insert(h); | ||||
} | } | ||||
/** Count the hits */ | /** Count the hits */ | ||||
uint32_t count = 0; | uint32_t count = 0; | ||||
for (uint256 &h : hashes) { | for (const uint256 &h : hashes) { | ||||
count += set.contains(h, false); | count += set.contains(h, false); | ||||
} | } | ||||
double hit_rate = double(count) / double(n_insert); | double hit_rate = double(count) / double(n_insert); | ||||
return hit_rate; | return hit_rate; | ||||
} | } | ||||
/** The normalized hit rate for a given load. | /** The normalized hit rate for a given load. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Lines | struct block_activity { | ||||
} | } | ||||
} | } | ||||
for (uint32_t i = 0; i < n_insert / 4; ++i) { | for (uint32_t i = 0; i < n_insert / 4; ++i) { | ||||
reads.push_back(inserts[i]); | reads.push_back(inserts[i]); | ||||
} | } | ||||
for (uint32_t i = n_insert - (n_insert / 4); i < n_insert; ++i) { | for (uint32_t i = n_insert - (n_insert / 4); i < n_insert; ++i) { | ||||
reads.push_back(inserts[i]); | reads.push_back(inserts[i]); | ||||
} | } | ||||
for (auto h : inserts) { | for (const auto &h : inserts) { | ||||
c.insert(h); | c.insert(h); | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
const uint32_t BLOCK_SIZE = 1000; | const uint32_t BLOCK_SIZE = 1000; | ||||
// We expect window size 60 to perform reasonably given that each epoch | // We expect window size 60 to perform reasonably given that each epoch | ||||
// stores 45% of the cache size (~472k). | // stores 45% of the cache size (~472k). | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |