@@ -33,7 +33,8 @@ using ::benchmark::DoNotOptimize;
3333
3434// Helper function used to implement two similar benchmarks that the given input
3535// key is NOT present in the set.
36- template <template <class ...> class SetT , size_t kValueSizeT , bool kLookup >
36+ template <template <class ...> class SetT , size_t kValueSizeT , bool kLookup ,
37+ bool kIncludeHotAccesses >
3738static void FindMiss_Cold (benchmark::State& state) {
3839 using Set = SetT<Value<kValueSizeT >, Hash, Eq>;
3940
@@ -52,7 +53,10 @@ static void FindMiss_Cold(benchmark::State& state) {
5253 std::conditional_t <kLookup , std::vector<Set>&, std::vector<Set>> sets =
5354 cached_sets;
5455
56+ Set hot_set;
57+
5558 int warmup = 5 ;
59+ int cold_access_counter = 0 ;
5660 while (true ) {
5761 for (uint32_t key : keys) {
5862 if (--warmup < 0 && !state.KeepRunningBatch (sets.size ())) return ;
@@ -66,6 +70,23 @@ static void FindMiss_Cold(benchmark::State& state) {
6670 auto res = set.insert (key);
6771 DoNotOptimize (res);
6872 }
73+
74+ if constexpr (kIncludeHotAccesses ) {
75+ if ((cold_access_counter++) % 32 == 0 ) {
76+ for (uint32_t hot_key : keys) {
77+ if (kLookup ) {
78+ auto res = hot_set.find (hot_key);
79+ DoNotOptimize (res);
80+ } else {
81+ auto res = hot_set.insert (hot_key);
82+ DoNotOptimize (res);
83+ }
84+ }
85+ if (!kLookup ) {
86+ hot_set.clear ();
87+ }
88+ }
89+ }
6990 }
7091 if (!kLookup ) {
7192 // PauseTiming()/ResumeTiming() are relatively expensive, but it is OK
@@ -86,15 +107,27 @@ static void FindMiss_Cold(benchmark::State& state) {
86107// assert(set.find(key) == set.end());
87108template <template <class ...> class SetT , size_t kValueSizeT >
88109static void BM_SWISSMAP_FindMiss_Cold (benchmark::State& state) {
89- return FindMiss_Cold<SetT, kValueSizeT , /* kLookup=*/ true >(state);
110+ return FindMiss_Cold<SetT, kValueSizeT , /* kLookup=*/ true ,
111+ /* kIncludeHotAccesses=*/ false >(state);
90112}
91113
92114// Measures the time it takes to `insert` an existent element.
93115//
94116// assert(set.insert(key).second);
95117template <template <class ...> class SetT , size_t kValueSizeT >
96118static void BM_SWISSMAP_InsertMiss_Cold (benchmark::State& state) {
97- return FindMiss_Cold<SetT, kValueSizeT , /* kLookup=*/ false >(state);
119+ return FindMiss_Cold<SetT, kValueSizeT , /* kLookup=*/ false ,
120+ /* kIncludeHotAccesses=*/ false >(state);
121+ }
122+
123+ // Measures the time it takes to `insert` an existent element.
124+ // Performs both hot and cold accesses.
125+ //
126+ // assert(set.insert(key).second);
127+ template <template <class ...> class SetT , size_t kValueSizeT >
128+ static void BM_SWISSMAP_InsertMiss (benchmark::State& state) {
129+ return FindMiss_Cold<SetT, kValueSizeT , /* kLookup=*/ false ,
130+ /* kIncludeHotAccesses=*/ true >(state);
98131}
99132
100133// Helper function used to implement two similar benchmarks defined below that
@@ -354,6 +387,8 @@ void RegisterColdBenchmarks() {
354387 ADD_SWISSMAP_BENCHMARKS_TO_LIST (benchmarks, BM_SWISSMAP_FindMiss_Cold, 64 );
355388 ADD_SWISSMAP_BENCHMARKS_TO_LIST (benchmarks, BM_SWISSMAP_InsertMiss_Cold, 4 );
356389 ADD_SWISSMAP_BENCHMARKS_TO_LIST (benchmarks, BM_SWISSMAP_InsertMiss_Cold, 64 );
390+ ADD_SWISSMAP_BENCHMARKS_TO_LIST (benchmarks, BM_SWISSMAP_InsertMiss, 4 );
391+ ADD_SWISSMAP_BENCHMARKS_TO_LIST (benchmarks, BM_SWISSMAP_InsertMiss, 64 );
357392 ADD_SWISSMAP_BENCHMARKS_TO_LIST (benchmarks, BM_SWISSMAP_FindHit_Cold, 4 );
358393 ADD_SWISSMAP_BENCHMARKS_TO_LIST (benchmarks, BM_SWISSMAP_FindHit_Cold, 64 );
359394 ADD_SWISSMAP_BENCHMARKS_TO_LIST (benchmarks, BM_SWISSMAP_InsertHit_Cold, 4 );
0 commit comments