Skip to content

Commit

Permalink
bench swap, is already fast
Browse files Browse the repository at this point in the history
  • Loading branch information
martinus committed Jul 4, 2022
1 parent 676fbae commit 1b0542e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
3 changes: 0 additions & 3 deletions test/bench/copy.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#include <ankerl/unordered_dense.h>
#include <app/name_of_type.h>
#include <app/nanobench.h>
#include <app/robin_hood.h>

#include <chrono>
#include <doctest.h>
#include <fmt/format.h>

#include <array>
#include <unordered_map>

template <typename Map>
Expand Down
48 changes: 48 additions & 0 deletions test/bench/swap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <ankerl/unordered_dense.h>
#include <app/nanobench.h>
#include <app/robin_hood.h>

#include <cstdint>
#include <doctest.h>
#include <fmt/format.h>

#include <iostream>
#include <unordered_map>

namespace {

template <typename Map>
void bench(std::string_view name) {
Map a;
Map b;
ankerl::nanobench::Rng rng(123);

ankerl::nanobench::Bench bench;
for (size_t j = 0; j < 10000; ++j) {
a[rng()];
b[rng()];
}
bench.run(fmt::format("swap {}", name), [&] {
std::swap(a, b);
});
ankerl::nanobench::doNotOptimizeAway(&a);
ankerl::nanobench::doNotOptimizeAway(&b);
}

} // namespace

TEST_CASE("bench_swap_rhn" * doctest::test_suite("bench") * doctest::skip()) {
bench<robin_hood::unordered_node_map<uint64_t, uint64_t>>("robin_hood::unordered_node_map");
}

TEST_CASE("bench_swap_rhf" * doctest::test_suite("bench") * doctest::skip()) {
bench<robin_hood::unordered_flat_map<uint64_t, uint64_t>>("robin_hood::unordered_flat_map");
}

TEST_CASE("bench_swap_std" * doctest::test_suite("bench") * doctest::skip()) {
bench<std::unordered_map<uint64_t, uint64_t>>("std::unordered_map");
}

TEST_CASE("bench_swap_udm" * doctest::test_suite("bench") * doctest::skip()) {
bench<ankerl::unordered_dense::map<uint64_t, uint64_t>>("ankerl::unordered_dense::map");
}
1 change: 1 addition & 0 deletions test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test_sources = [
'bench/copy.cpp',
'bench/find_random.cpp',
'bench/quick_overall_map.cpp',
'bench/swap.cpp',
'unit/assign_to_move.cpp',
'unit/assignment_combinations.cpp',
'unit/at.cpp',
Expand Down

0 comments on commit 1b0542e

Please sign in to comment.