MCPcopy Create free account
hub / github.com/LUX-Core/lux / test_cache

Function test_cache

src/test/cuckoocache_tests.cpp:80–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78 */
79template <typename Cache>
80double test_cache(size_t megabytes, double load)
81{
82 insecure_rand = FastRandomContext(true);
83 std::vector<uint256> hashes;
84 Cache set{};
85 size_t bytes = megabytes * (1 << 20);
86 set.setup_bytes(bytes);
87 uint32_t n_insert = static_cast<uint32_t>(load * (bytes / sizeof(uint256)));
88 hashes.resize(n_insert);
89 for (uint32_t i = 0; i < n_insert; ++i) {
90 uint32_t* ptr = (uint32_t*)hashes[i].begin();
91 for (uint8_t j = 0; j < 8; ++j)
92 *(ptr++) = insecure_rand.rand32();
93 }
94 /** We make a copy of the hashes because future optimizations of the
95 * cuckoocache may overwrite the inserted element, so the test is
96 * "future proofed".
97 */
98 std::vector<uint256> hashes_insert_copy = hashes;
99 /** Do the insert */
100 for (uint256& h : hashes_insert_copy)
101 set.insert(h);
102 /** Count the hits */
103 uint32_t count = 0;
104 for (uint256& h : hashes)
105 count += set.contains(h, false);
106 double hit_rate = ((double)count) / ((double)n_insert);
107 return hit_rate;
108}
109
110/** The normalized hit rate for a given load.
111 *

Callers

nothing calls this directly

Calls 5

setup_bytesMethod · 0.45
resizeMethod · 0.45
beginMethod · 0.45
insertMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected