diff options
author | Louis Dionne <ldionne.2@gmail.com> | 2023-09-21 05:11:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-21 05:11:49 -0400 |
commit | 8bbcc6d548e86c6fbd621ef138aefddeb676e367 (patch) | |
tree | 1d873d4cbf159c3ced85ded1e44050390c8d5ac2 /libcxx/benchmarks | |
parent | e46de4e54f63eb4088ca351253768b5db8cf1985 (diff) | |
download | llvm-8bbcc6d548e86c6fbd621ef138aefddeb676e367.zip llvm-8bbcc6d548e86c6fbd621ef138aefddeb676e367.tar.gz llvm-8bbcc6d548e86c6fbd621ef138aefddeb676e367.tar.bz2 |
[libc++] Add test coverage for unordered containers comparison (#66692)
This patch is a melting pot of changes picked up from
https://llvm.org/D61878. It adds a few tests checking corner cases of
unordered containers comparison and adds benchmarks for a few
unordered_set operations.
Diffstat (limited to 'libcxx/benchmarks')
-rw-r--r-- | libcxx/benchmarks/ContainerBenchmarks.h | 31 | ||||
-rw-r--r-- | libcxx/benchmarks/unordered_set_operations.bench.cpp | 19 |
2 files changed, 50 insertions, 0 deletions
diff --git a/libcxx/benchmarks/ContainerBenchmarks.h b/libcxx/benchmarks/ContainerBenchmarks.h index 5ab6f61..071e46c 100644 --- a/libcxx/benchmarks/ContainerBenchmarks.h +++ b/libcxx/benchmarks/ContainerBenchmarks.h @@ -179,6 +179,37 @@ static void BM_Rehash(benchmark::State& st, Container c, GenInputs gen) { } } +template <class Container, class GenInputs> +static void BM_Compare_same_container(benchmark::State& st, Container, GenInputs gen) { + auto in = gen(st.range(0)); + Container c1(in.begin(), in.end()); + Container c2 = c1; + + benchmark::DoNotOptimize(&(*c1.begin())); + benchmark::DoNotOptimize(&(*c2.begin())); + while (st.KeepRunning()) { + bool res = c1 == c2; + benchmark::DoNotOptimize(&res); + benchmark::ClobberMemory(); + } +} + +template <class Container, class GenInputs> +static void BM_Compare_different_containers(benchmark::State& st, Container, GenInputs gen) { + auto in1 = gen(st.range(0)); + auto in2 = gen(st.range(0)); + Container c1(in1.begin(), in1.end()); + Container c2(in2.begin(), in2.end()); + + benchmark::DoNotOptimize(&(*c1.begin())); + benchmark::DoNotOptimize(&(*c2.begin())); + while (st.KeepRunning()) { + bool res = c1 == c2; + benchmark::DoNotOptimize(&res); + benchmark::ClobberMemory(); + } +} + } // end namespace ContainerBenchmarks #endif // BENCHMARK_CONTAINER_BENCHMARKS_H diff --git a/libcxx/benchmarks/unordered_set_operations.bench.cpp b/libcxx/benchmarks/unordered_set_operations.bench.cpp index 96aa2e0..d49de57 100644 --- a/libcxx/benchmarks/unordered_set_operations.bench.cpp +++ b/libcxx/benchmarks/unordered_set_operations.bench.cpp @@ -290,6 +290,25 @@ BENCHMARK_CAPTURE(BM_Rehash, BENCHMARK_CAPTURE(BM_Rehash, unordered_set_int_arg, std::unordered_set<int>{}, getRandomIntegerInputs<int>) ->Arg(TestNumInputs); +//----------------------------------------------------------------------------// +// BM_Compare +// ---------------------------------------------------------------------------// + +BENCHMARK_CAPTURE( + BM_Compare_same_container, unordered_set_string, std::unordered_set<std::string>{}, getRandomStringInputs) + ->Arg(TestNumInputs); + +BENCHMARK_CAPTURE(BM_Compare_same_container, unordered_set_int, std::unordered_set<int>{}, getRandomIntegerInputs<int>) + ->Arg(TestNumInputs); + +BENCHMARK_CAPTURE( + BM_Compare_different_containers, unordered_set_string, std::unordered_set<std::string>{}, getRandomStringInputs) + ->Arg(TestNumInputs); + +BENCHMARK_CAPTURE( + BM_Compare_different_containers, unordered_set_int, std::unordered_set<int>{}, getRandomIntegerInputs<int>) + ->Arg(TestNumInputs); + /////////////////////////////////////////////////////////////////////////////// BENCHMARK_CAPTURE(BM_InsertDuplicate, unordered_set_int, std::unordered_set<int>{}, getRandomIntegerInputs<int>) ->Arg(TestNumInputs); |