11#include <boost/test/unit_test.hpp>
15#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;
63 set.setup_bytes(bytes);
82 count += set.contains(h,
false);
106 return hits * std::max(load, 1.0);
118 for (
double load = 0.1; load < 2; load *= 2) {
128template <
typename Cache>
133 std::vector<uint256>
hashes;
136 set.setup_bytes(bytes);
193template <
typename Cache>
198 std::vector<uint256>
hashes;
201 set.setup_bytes(bytes);
214 std::shared_mutex
mtx;
218 std::unique_lock<std::shared_mutex>
l(
mtx);
226 std::vector<std::thread>
threads;
233 std::shared_lock<std::shared_mutex>
l(
mtx);
235 size_t start =
ntodo*x;
236 size_t end =
ntodo*(x+1);
237 for (
uint32_t i = start; i < end; ++i) {
238 bool contains = set.contains(
hashes[i],
true);
248 std::unique_lock<std::shared_mutex>
l(
mtx);
286template <
typename Cache>
312 std::vector<uint256>
reads;
337 const double load = 10;
339 const size_t bytes =
megabytes * (1 << 20);
342 std::vector<block_activity>
hashes;
344 set.setup_bytes(bytes);
346 std::deque<block_activity>
last_few;
352 for (
uint32_t i = 0; i < total; ++i) {
359 count += set.contains(
act.reads.back(),
true);
360 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 megabytes)
void test_cache_erase(size_t megabytes)
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 megabytes, double load)
This helper returns the hit rate when megabytes*load worth of entries are inserted into a megabytes s...
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.