diff --git a/benchmarks/set_find.pass.cpp b/benchmarks/set_find.pass.cpp deleted file mode 100644 index 32f90266d..000000000 --- a/benchmarks/set_find.pass.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include - -#include "benchmark/benchmark_api.h" - -template -std::vector getInputs(size_t N) { - std::vector inputs; - for (size_t i=0; i < N; ++i) { - inputs.push_back(i); - } - return inputs; -} - -template -void BM_SetLookup(benchmark::State& st, Container c, Inputs const& in) { - c.insert(in.begin(), in.end()); - const auto end = in.end(); - while (st.KeepRunning()) { - for (auto it = in.begin(); it != end; ++it) { - benchmark::DoNotOptimize(c.find(*it++)); - } - } -} -BENCHMARK_CAPTURE(BM_SetLookup, uint32_lookup, - std::unordered_set{}, getInputs(1024)); - -BENCHMARK_MAIN() diff --git a/benchmarks/unordered_set_operations.bench.cpp b/benchmarks/unordered_set_operations.bench.cpp new file mode 100644 index 000000000..c9ee689f6 --- /dev/null +++ b/benchmarks/unordered_set_operations.bench.cpp @@ -0,0 +1,44 @@ +#include +#include +#include + +#include "benchmark/benchmark_api.h" + +template +std::vector getInputs(size_t N) { + std::vector inputs; + for (size_t i=0; i < N; ++i) { + inputs.push_back(i); + } + return inputs; +} + +template +void BM_SetInsert(benchmark::State& st, Container c, Inputs const& in) { + const auto end = in.end(); + while (st.KeepRunning()) { + c.clear(); + for (auto it = in.begin(); it != end; ++it) { + benchmark::DoNotOptimize(c.insert(*it)); + } + benchmark::DoNotOptimize(c); + } +} +BENCHMARK_CAPTURE(BM_SetInsert, uint32_insert, + std::unordered_set{}, getInputs(1024)); + +template +void BM_SetFind(benchmark::State& st, Container c, Inputs const& in) { + c.insert(in.begin(), in.end()); + const auto end = in.end(); + while (st.KeepRunning()) { + for (auto it = in.begin(); it != end; ++it) { + benchmark::DoNotOptimize(c.find(*it)); + } + } +} +BENCHMARK_CAPTURE(BM_SetFind, uint32_lookup, + std::unordered_set{}, getInputs(1024)); + + +BENCHMARK_MAIN()