-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[libc++] Add more benchmarks for the associative container hint interfaces #162840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++] Add more benchmarks for the associative container hint interfaces #162840
Conversation
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) ChangesThe current benchmarks test a very specific case, which makes them rather misleading. This adds new benchmarks so we have better coverage. Full diff: https://github.com/llvm/llvm-project/pull/162840.diff 1 Files Affected:
diff --git a/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h b/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
index b39569812640b..22a6d0d753b0c 100644
--- a/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
+++ b/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
@@ -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));
- 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];
@@ -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)) {
@@ -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) {
|
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)); |
There was a problem hiding this comment.
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.
…faces (llvm#162840) The current benchmarks test a very specific case, which makes them rather misleading. This adds new benchmarks so we have better coverage.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/169/builds/15918 Here is the relevant piece of the build log for the reference
|
…faces (llvm#162840) The current benchmarks test a very specific case, which makes them rather misleading. This adds new benchmarks so we have better coverage.
The current benchmarks test a very specific case, which makes them rather misleading. This adds new benchmarks so we have better coverage.