Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,19 @@ void associative_container_benchmarks(std::string container) {
// The insert(hint, ...) methods are only relevant for ordered containers, and we lack
// a good way to compute a hint for unordered ones.
if constexpr (is_ordered_container) {
bench("insert(hint, value) (good hint)", [=](auto& st) {
auto insert_good_hint_bench = [=](bool bench_end_iter, auto& st) {
const std::size_t size = st.range(0);
std::vector<Value> in = make_value_types(generate_unique_keys(size + 1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could consider returning a std::set from make_value_types instead, that would call out explicitly that the data is sorted and unique, and would make stuff like this easier. OK to do in a follow-up though.

Value to_insert = in.back();
in.pop_back();
auto skipped_val = bench_end_iter ? in.size() - 1 : in.size() / 2;
Value to_insert = in[skipped_val];
{ // Remove the element
std::vector<Value> tmp;
tmp.reserve(in.size() - 1);
for (size_t i = 0; i != in.size(); ++i)
if (i != skipped_val)
tmp.emplace_back(in[i]);
in = std::move(tmp);
}

std::vector<Container> c(BatchSize, Container(in.begin(), in.end()));
typename Container::iterator hints[BatchSize];
Expand All @@ -332,13 +340,23 @@ void associative_container_benchmarks(std::string container) {
}
st.ResumeTiming();
}
});
};
bench("insert(hint, value) (good hint, end)", [=](auto& state) { insert_good_hint_bench(true, state); });
bench("insert(hint, value) (good hint, middle)", [=](auto& state) { insert_good_hint_bench(false, state); });

bench("insert(hint, value) (bad hint)", [=](auto& st) {
auto insert_bad_hint_bench = [=](bool bench_end_iter, auto& st) {
const std::size_t size = st.range(0);
std::vector<Value> in = make_value_types(generate_unique_keys(size + 1));
Value to_insert = in.back();
in.pop_back();
auto skipped_val = bench_end_iter ? in.size() - 1 : in.size() / 2;
Value to_insert = in[skipped_val];
{ // Remove the element
std::vector<Value> tmp;
tmp.reserve(in.size() - 1);
for (size_t i = 0; i != in.size(); ++i)
if (i != skipped_val)
tmp.emplace_back(in[i]);
in = std::move(tmp);
}
std::vector<Container> c(BatchSize, Container(in.begin(), in.end()));

while (st.KeepRunningBatch(BatchSize)) {
Expand All @@ -355,7 +373,10 @@ void associative_container_benchmarks(std::string container) {
}
st.ResumeTiming();
}
});
};

bench("insert(hint, value) (bad hint, end)", [=](auto& state) { insert_bad_hint_bench(true, state); });
bench("insert(hint, value) (bad hint, middle)", [=](auto& state) { insert_bad_hint_bench(false, state); });
}

bench("insert(iterator, iterator) (all new keys)", [=](auto& st) {
Expand Down
Loading