Skip to content

Commit c339067

Browse files
andreas-abelcopybara-github
authored andcommitted
Create a copy of the sets vector in InsertMiss_Hot
The benchmark loop of the InsertMiss_Hot benchmark modifies the sets in the vector. Therefore, we need to make a copy. Otherwise, repeated calls to `InsertMiss_Hot` (e.g., if the `--benchmark_repetitions` flag is set to a value larger than 1) start with increasingly larger sets, and thus the runtime of the benchmark grows with each repetition. PiperOrigin-RevId: 747418678 Change-Id: I3327d6bbd6b9cb148c45100985f21e6148c60ffd
1 parent 9f444d0 commit c339067

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

fleetbench/swissmap/hot_swissmap_benchmark.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <cstdint>
1919
#include <memory>
2020
#include <string>
21+
#include <type_traits>
2122
#include <utility>
2223
#include <vector>
2324

@@ -50,8 +51,11 @@ void FindMiss_Hot(benchmark::State& state) {
5051
static constexpr size_t kOpsPerKey = 512;
5152

5253
auto& sc = SetsCache<Set>::GetInstance();
53-
auto& sets = sc.GetGeneratedSets(state.range(0), kMinTotalKeyCount,
54-
static_cast<Density>(state.range(1)));
54+
// If kLookup is false, we need to create a copy of the cached sets vector
55+
// because the benchmark loop modifies it.
56+
std::conditional_t<kLookup, std::vector<Set>&, std::vector<Set>> sets =
57+
sc.GetGeneratedSets(state.range(0), kMinTotalKeyCount,
58+
static_cast<Density>(state.range(1)));
5559
const size_t keys_per_set = kMinTotalKeyCount / sets.size();
5660

5761
while (state.KeepRunningBatch(sets.size() * keys_per_set * kOpsPerKey)) {

0 commit comments

Comments
 (0)