MCPcopy Create free account
hub / github.com/ElementsProject/elements / test_cache

Function test_cache

src/test/cuckoocache_tests.cpp:54–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52 */
53template <typename Cache>
54static double test_cache(size_t megabytes, double load)
55{
56 SeedInsecureRand(SeedRand::ZEROS);
57 std::vector<uint256> hashes;
58 Cache set{};
59 size_t bytes = megabytes * (1 << 20);
60 set.setup_bytes(bytes);
61 uint32_t n_insert = static_cast<uint32_t>(load * (bytes / sizeof(uint256)));
62 hashes.resize(n_insert);
63 for (uint32_t i = 0; i < n_insert; ++i) {
64 uint32_t* ptr = (uint32_t*)hashes[i].begin();
65 for (uint8_t j = 0; j < 8; ++j)
66 *(ptr++) = InsecureRand32();
67 }
68 /** We make a copy of the hashes because future optimizations of the
69 * cuckoocache may overwrite the inserted element, so the test is
70 * "future proofed".
71 */
72 std::vector<uint256> hashes_insert_copy = hashes;
73 /** Do the insert */
74 for (const uint256& h : hashes_insert_copy)
75 set.insert(h);
76 /** Count the hits */
77 uint32_t count = 0;
78 for (const uint256& h : hashes)
79 count += set.contains(h, false);
80 double hit_rate = ((double)count) / ((double)n_insert);
81 return hit_rate;
82}
83
84/** The normalized hit rate for a given load.
85 *

Callers

nothing calls this directly

Calls 7

SeedInsecureRandFunction · 0.85
InsecureRand32Function · 0.85
setup_bytesMethod · 0.45
resizeMethod · 0.45
beginMethod · 0.45
insertMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected