@@ -305,11 +305,19 @@ void associative_container_benchmarks(std::string container) {
305305 // The insert(hint, ...) methods are only relevant for ordered containers, and we lack
306306 // a good way to compute a hint for unordered ones.
307307 if constexpr (is_ordered_container) {
308- bench ( " insert(hint, value) (good hint) " , [=](auto & st) {
308+ auto insert_good_hint_bench = [=](bool bench_end_iter, auto & st) {
309309 const std::size_t size = st.range (0 );
310310 std::vector<Value> in = make_value_types (generate_unique_keys (size + 1 ));
311- Value to_insert = in.back ();
312- in.pop_back ();
311+ auto skipped_val = bench_end_iter ? in.size () - 1 : in.size () / 2 ;
312+ Value to_insert = in[skipped_val];
313+ { // Remove the element
314+ std::vector<Value> tmp;
315+ tmp.reserve (in.size () - 1 );
316+ for (size_t i = 0 ; i != in.size (); ++i)
317+ if (i != skipped_val)
318+ tmp.emplace_back (in[i]);
319+ in = std::move (tmp);
320+ }
313321
314322 std::vector<Container> c (BatchSize, Container (in.begin (), in.end ()));
315323 typename Container::iterator hints[BatchSize];
@@ -332,13 +340,23 @@ void associative_container_benchmarks(std::string container) {
332340 }
333341 st.ResumeTiming ();
334342 }
335- });
343+ };
344+ bench (" insert(hint, value) (good hint, end)" , [=](auto & state) { insert_good_hint_bench (true , state); });
345+ bench (" insert(hint, value) (good hint, middle)" , [=](auto & state) { insert_good_hint_bench (false , state); });
336346
337- bench ( " insert(hint, value) (bad hint) " , [=](auto & st) {
347+ auto insert_bad_hint_bench = [=](bool bench_end_iter, auto & st) {
338348 const std::size_t size = st.range (0 );
339349 std::vector<Value> in = make_value_types (generate_unique_keys (size + 1 ));
340- Value to_insert = in.back ();
341- in.pop_back ();
350+ auto skipped_val = bench_end_iter ? in.size () - 1 : in.size () / 2 ;
351+ Value to_insert = in[skipped_val];
352+ { // Remove the element
353+ std::vector<Value> tmp;
354+ tmp.reserve (in.size () - 1 );
355+ for (size_t i = 0 ; i != in.size (); ++i)
356+ if (i != skipped_val)
357+ tmp.emplace_back (in[i]);
358+ in = std::move (tmp);
359+ }
342360 std::vector<Container> c (BatchSize, Container (in.begin (), in.end ()));
343361
344362 while (st.KeepRunningBatch (BatchSize)) {
@@ -355,7 +373,10 @@ void associative_container_benchmarks(std::string container) {
355373 }
356374 st.ResumeTiming ();
357375 }
358- });
376+ };
377+
378+ bench (" insert(hint, value) (bad hint, end)" , [=](auto & state) { insert_bad_hint_bench (true , state); });
379+ bench (" insert(hint, value) (bad hint, middle)" , [=](auto & state) { insert_bad_hint_bench (false , state); });
359380 }
360381
361382 bench (" insert(iterator, iterator) (all new keys)" , [=](auto & st) {
0 commit comments