bench: make EvictionProtection.* work with any number of iterations

Moves copying of the setup into the benchmark loop so it is possible
to run the loop for an arbitrary number of times.

The overhead due to copying the candidates inside the loop is about 3%.
This commit is contained in:
Martin Ankerl 2021-09-18 08:13:03 +02:00
parent 153e6860e8
commit 9fef832932
No known key found for this signature in database
GPG key ID: FBEAAD7FC6FFFE81

View file

@ -20,19 +20,17 @@ static void EvictionProtectionCommon(
{
using Candidates = std::vector<NodeEvictionCandidate>;
FastRandomContext random_context{true};
bench.warmup(100).epochIterations(1100);
Candidates candidates{GetRandomNodeEvictionCandidates(num_candidates, random_context)};
for (auto& c : candidates) {
candidate_setup_fn(c);
}
std::vector<Candidates> copies{
static_cast<size_t>(bench.epochs() * bench.epochIterations()), candidates};
size_t i{0};
bench.run([&] {
ProtectEvictionCandidatesByRatio(copies.at(i));
++i;
// creating a copy has an overhead of about 3%, so it does not influence the benchmark results much.
auto copy = candidates;
ProtectEvictionCandidatesByRatio(copy);
});
}