12#include <boost/test/unit_test.hpp>
16#include <shared_mutex>
44 for (
int x = 0; x < 100000; ++x) {
45 cc.insert(m_rng.rand256());
47 for (
int x = 0; x < 100000; ++x) {
56template <
typename Cache>
60 std::vector<uint256>
hashes;
62 set.setup_bytes(bytes);
81 count += set.contains(h,
false);
105 return hits * std::max(load, 1.0);
116 for (
double load = 0.1; load < 2; load *= 2) {
126template <
typename Cache>
131 std::vector<uint256>
hashes;
133 set.setup_bytes(bytes);
189template <
typename Cache>
194 std::vector<uint256>
hashes;
196 set.setup_bytes(bytes);
209 std::shared_mutex
mtx;
213 std::unique_lock<std::shared_mutex>
l(
mtx);
221 std::vector<std::thread>
threads;
228 std::shared_lock<std::shared_mutex>
l(
mtx);
230 size_t start =
ntodo*x;
231 size_t end =
ntodo*(x+1);
232 for (
uint32_t i = start; i < end; ++i) {
233 bool contains = set.contains(
hashes[i],
true);
243 std::unique_lock<std::shared_mutex>
l(
mtx);
280template <
typename Cache>
306 std::vector<uint256>
reads;
331 const double load = 10;
332 const size_t bytes{4
_MiB};
335 std::vector<block_activity>
hashes;
337 set.setup_bytes(bytes);
339 std::deque<block_activity>
last_few;
345 for (
uint32_t i = 0; i < total; ++i) {
352 count += set.contains(
act.reads.back(),
true);
353 act.reads.pop_back();
cache implements a cache with properties similar to a cuckoo-set.
std::pair< uint32_t, size_t > setup_bytes(size_t bytes)
setup_bytes is a convenience function which accounts for internal memory usage when deciding how many...
uint32_t rand32() noexcept
Generate a random 32-bit integer.
BOOST_AUTO_TEST_CASE(test_cuckoocache_no_fakes)
BOOST_FIXTURE_TEST_CASE(cuckoocache_hit_rate_ok, HitRateTest)
Check the hit rate on loads ranging from 0.1 to 1.6.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
void SeedRandomForTest(SeedRand seed)
Seed the global RNG state and m_rng for testing and log the seed value.
void test_cache_erase_parallel(size_t bytes)
void test_cache_erase(size_t bytes)
This helper checks that erased elements are preferentially inserted onto and that the hit rate of "fr...
void test_cache_generations()
double test_cache(size_t bytes, double load)
This helper returns the hit rate when bytes*load worth of entries are inserted into a bytes sized cac...
static double normalize_hit_rate(double hits, double load)
The normalized hit rate for a given load.
@ ZEROS
Seed with a compile time constant of zeros.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.