![]() |
Bitcoin Core
25.99.0
P2P Digital Currency
|
#include <cuckoocache.h>
#include <random.h>
#include <script/sigcache.h>
#include <test/util/random.h>
#include <test/util/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <deque>
#include <mutex>
#include <shared_mutex>
#include <thread>
#include <vector>
Go to the source code of this file.
Functions | |
BOOST_AUTO_TEST_SUITE (cuckoocache_tests) | |
Test Suite for CuckooCache. More... | |
BOOST_AUTO_TEST_CASE (test_cuckoocache_no_fakes) | |
template<typename Cache > | |
static 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 sized cache. More... | |
static double | normalize_hit_rate (double hits, double load) |
The normalized hit rate for a given load. More... | |
BOOST_AUTO_TEST_CASE (cuckoocache_hit_rate_ok) | |
Check the hit rate on loads ranging from 0.1 to 1.6. More... | |
template<typename Cache > | |
static void | test_cache_erase (size_t megabytes) |
This helper checks that erased elements are preferentially inserted onto and that the hit rate of "fresher" keys is reasonable. More... | |
BOOST_AUTO_TEST_CASE (cuckoocache_erase_ok) | |
template<typename Cache > | |
static void | test_cache_erase_parallel (size_t megabytes) |
BOOST_AUTO_TEST_CASE (cuckoocache_erase_parallel_ok) | |
template<typename Cache > | |
static void | test_cache_generations () |
BOOST_AUTO_TEST_CASE (cuckoocache_generations) | |
BOOST_AUTO_TEST_SUITE_END () | |
BOOST_AUTO_TEST_CASE | ( | cuckoocache_erase_ok | ) |
Definition at line 182 of file cuckoocache_tests.cpp.
BOOST_AUTO_TEST_CASE | ( | cuckoocache_erase_parallel_ok | ) |
Definition at line 271 of file cuckoocache_tests.cpp.
BOOST_AUTO_TEST_CASE | ( | cuckoocache_generations | ) |
Definition at line 368 of file cuckoocache_tests.cpp.
BOOST_AUTO_TEST_CASE | ( | cuckoocache_hit_rate_ok | ) |
Check the hit rate on loads ranging from 0.1 to 1.6.
Arbitrarily selected Hit Rate threshold that happens to work for this test as a lower bound on performance.
Definition at line 109 of file cuckoocache_tests.cpp.
BOOST_AUTO_TEST_CASE | ( | test_cuckoocache_no_fakes | ) |
BOOST_AUTO_TEST_SUITE | ( | cuckoocache_tests | ) |
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END | ( | ) |
|
static |
The normalized hit rate for a given load.
The semantics are a little confusing, so please see the below explanation.
Examples:
This is basically the right semantics, but has a bit of a glitch depending on how you measure around load 1.0 as after load 1.0 your normalized hit rate becomes effectively perfect, ignoring freshness.
Definition at line 103 of file cuckoocache_tests.cpp.
|
static |
This helper returns the hit rate when megabytes*load worth of entries are inserted into a megabytes sized cache.
We make a copy of the hashes because future optimizations of the cuckoocache may overwrite the inserted element, so the test is "future proofed".
Do the insert
Count the hits
Definition at line 56 of file cuckoocache_tests.cpp.
|
static |
This helper checks that erased elements are preferentially inserted onto and that the hit rate of "fresher" keys is reasonable.
We make a copy of the hashes because future optimizations of the cuckoocache may overwrite the inserted element, so the test is "future proofed".
Insert the first half
Erase the first quarter
Insert the second half
elements that we marked as erased but are still there
elements that we did not erase but are older
elements that were most recently inserted
Definition at line 126 of file cuckoocache_tests.cpp.
|
static |
We make a copy of the hashes because future optimizations of the cuckoocache may overwrite the inserted element, so the test is "future proofed".
Grab lock to make sure we release inserts
Insert the first half
Spin up 3 threads to run contains with erase.
Erase the first quarter
Each thread is emplaced with x copy-by-value
Wait for all threads to finish
Grab lock to make sure we observe erases
Insert the second half
elements that we marked erased but that are still there
elements that we did not erase but are older
elements that were most recently inserted
Definition at line 189 of file cuckoocache_tests.cpp.
|
static |