mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 03:32:35 +08:00
Skip chash computation in insert/emplace if the unconstrained hash matches.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@276549 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -34,6 +34,38 @@ void BM_InsertValueRehash(benchmark::State& st, Container c, GenInputs gen) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class Container, class GenInputs>
|
||||
void BM_InsertDuplicate(benchmark::State& st, Container c, GenInputs gen) {
|
||||
auto in = gen(st.range_x());
|
||||
const auto end = in.end();
|
||||
c.insert(in.begin(), in.end());
|
||||
benchmark::DoNotOptimize(&c);
|
||||
benchmark::DoNotOptimize(&in);
|
||||
while (st.KeepRunning()) {
|
||||
for (auto it = in.begin(); it != end; ++it) {
|
||||
benchmark::DoNotOptimize(&(*c.insert(*it).first));
|
||||
}
|
||||
benchmark::ClobberMemory();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class Container, class GenInputs>
|
||||
void BM_EmplaceDuplicate(benchmark::State& st, Container c, GenInputs gen) {
|
||||
auto in = gen(st.range_x());
|
||||
const auto end = in.end();
|
||||
c.insert(in.begin(), in.end());
|
||||
benchmark::DoNotOptimize(&c);
|
||||
benchmark::DoNotOptimize(&in);
|
||||
while (st.KeepRunning()) {
|
||||
for (auto it = in.begin(); it != end; ++it) {
|
||||
benchmark::DoNotOptimize(&(*c.emplace(*it).first));
|
||||
}
|
||||
benchmark::ClobberMemory();
|
||||
}
|
||||
}
|
||||
|
||||
template <class Container, class GenInputs>
|
||||
static void BM_Find(benchmark::State& st, Container c, GenInputs gen) {
|
||||
auto in = gen(st.range_x());
|
||||
|
||||
@@ -130,4 +130,11 @@ inline std::vector<std::string> getReverseSortedStringInputs(size_t N) {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
inline std::vector<const char*> getRandomCStringInputs(size_t N) {
|
||||
static std::vector<std::string> inputs = getRandomStringInputs(N);
|
||||
std::vector<const char*> cinputs;
|
||||
for (auto const& str : inputs)
|
||||
cinputs.push_back(str.c_str());
|
||||
return cinputs;
|
||||
}
|
||||
#endif // BENCHMARK_GENERATE_INPUT_HPP
|
||||
|
||||
@@ -265,4 +265,42 @@ BENCHMARK_CAPTURE(BM_FindRehash,
|
||||
std::unordered_set<std::string>{},
|
||||
getRandomStringInputs)->Arg(TestNumInputs);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
BENCHMARK_CAPTURE(BM_InsertDuplicate,
|
||||
unordered_set_int,
|
||||
std::unordered_set<int>{},
|
||||
getRandomIntegerInputs<int>)->Arg(TestNumInputs);
|
||||
BENCHMARK_CAPTURE(BM_InsertDuplicate,
|
||||
unordered_set_string,
|
||||
std::unordered_set<std::string>{},
|
||||
getRandomStringInputs)->Arg(TestNumInputs);
|
||||
|
||||
BENCHMARK_CAPTURE(BM_EmplaceDuplicate,
|
||||
unordered_set_int,
|
||||
std::unordered_set<int>{},
|
||||
getRandomIntegerInputs<int>)->Arg(TestNumInputs);
|
||||
BENCHMARK_CAPTURE(BM_EmplaceDuplicate,
|
||||
unordered_set_string,
|
||||
std::unordered_set<std::string>{},
|
||||
getRandomStringInputs)->Arg(TestNumInputs);
|
||||
|
||||
BENCHMARK_CAPTURE(BM_InsertDuplicate,
|
||||
unordered_set_int_insert_arg,
|
||||
std::unordered_set<int>{},
|
||||
getRandomIntegerInputs<int>)->Arg(TestNumInputs);
|
||||
BENCHMARK_CAPTURE(BM_InsertDuplicate,
|
||||
unordered_set_string_insert_arg,
|
||||
std::unordered_set<std::string>{},
|
||||
getRandomStringInputs)->Arg(TestNumInputs);
|
||||
|
||||
BENCHMARK_CAPTURE(BM_EmplaceDuplicate,
|
||||
unordered_set_int_insert_arg,
|
||||
std::unordered_set<int>{},
|
||||
getRandomIntegerInputs<unsigned>)->Arg(TestNumInputs);
|
||||
|
||||
BENCHMARK_CAPTURE(BM_EmplaceDuplicate,
|
||||
unordered_set_string_arg,
|
||||
std::unordered_set<std::string>{},
|
||||
getRandomCStringInputs)->Arg(TestNumInputs);
|
||||
|
||||
BENCHMARK_MAIN()
|
||||
|
||||
@@ -1961,7 +1961,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const&
|
||||
if (__nd != nullptr)
|
||||
{
|
||||
for (__nd = __nd->__next_; __nd != nullptr &&
|
||||
__constrain_hash(__nd->__hash(), __bc) == __chash;
|
||||
(__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash);
|
||||
__nd = __nd->__next_)
|
||||
{
|
||||
if (key_eq()(__nd->__upcast()->__value_, __k))
|
||||
|
||||
Reference in New Issue
Block a user