MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / test_cache

Function test_cache

src/test/cuckoocache_tests.cpp:65–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63 */
64template <typename Cache>
65static double test_cache(size_t megabytes, double load)
66{
67 local_rand_ctx = FastRandomContext(true);
68 std::vector<uint256> hashes;
69 Cache set{};
70 size_t bytes = megabytes * (1 << 20);
71 set.setup_bytes(bytes);
72 uint32_t n_insert = static_cast<uint32_t>(load * (bytes / sizeof(uint256)));
73 hashes.resize(n_insert);
74 for (uint32_t i = 0; i < n_insert; ++i) {
75 uint32_t* ptr = (uint32_t*)hashes[i].begin();
76 for (uint8_t j = 0; j < 8; ++j)
77 *(ptr++) = local_rand_ctx.rand32();
78 }
79 /** We make a copy of the hashes because future optimizations of the
80 * cuckoocache may overwrite the inserted element, so the test is
81 * "future proofed".
82 */
83 std::vector<uint256> hashes_insert_copy = hashes;
84 /** Do the insert */
85 for (uint256& h : hashes_insert_copy)
86 set.insert(h);
87 /** Count the hits */
88 uint32_t count = 0;
89 for (uint256& h : hashes)
90 count += set.contains(h, false);
91 double hit_rate = ((double)count) / ((double)n_insert);
92 return hit_rate;
93}
94
95/** The normalized hit rate for a given load.
96 *

Callers

nothing calls this directly

Calls 7

FastRandomContextClass · 0.85
rand32Method · 0.80
setup_bytesMethod · 0.45
resizeMethod · 0.45
beginMethod · 0.45
insertMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected