Add a build of boost_unordered for benchmarking. (#4045)

This uses a header-only extraction of the Boost unordered hashtable
project to allow a trivial Bazel build and for us to benchmark against
it effectively.
This commit is contained in:
Chandler Carruth
2024-06-10 22:10:10 +00:00
committed by GitHub
parent 3be57b71e0
commit 26ead9addc
7 changed files with 69 additions and 9 deletions
+13 -4
View File
@@ -4,6 +4,7 @@
#include <benchmark/benchmark.h>
#include <boost/unordered/unordered_flat_map.hpp>
#include <type_traits>
#include "absl/container/flat_hash_map.h"
@@ -133,6 +134,7 @@ struct MapWrapperImpl<Map<KT, VT, MinSmallSize>> {
enum class MapOverride : uint8_t {
None,
Abseil,
Boost,
LLVM,
LLVMAndCarbonHash,
};
@@ -147,6 +149,10 @@ template <typename KeyT, typename ValueT, int MinSmallSize>
struct MapWrapperOverride<Map<KeyT, ValueT, MinSmallSize>, MapOverride::Abseil>
: MapWrapperImpl<absl::flat_hash_map<KeyT, ValueT>> {};
template <typename KeyT, typename ValueT, int MinSmallSize>
struct MapWrapperOverride<Map<KeyT, ValueT, MinSmallSize>, MapOverride::Boost>
: MapWrapperImpl<boost::unordered::unordered_flat_map<KeyT, ValueT>> {};
template <typename KeyT, typename ValueT, int MinSmallSize>
struct MapWrapperOverride<Map<KeyT, ValueT, MinSmallSize>, MapOverride::LLVM>
: MapWrapperImpl<llvm::DenseMap<KeyT, ValueT>> {};
@@ -170,10 +176,11 @@ auto ReportMetrics(const MapWrapper<MapT>& m_wrapper, benchmark::State& state)
}
// NOLINTBEGIN(bugprone-macro-parentheses): Parentheses are incorrect here.
#define MAP_BENCHMARK_ONE_OP_SIZE(NAME, APPLY, KT, VT) \
BENCHMARK(NAME<Map<KT, VT>>)->Apply(APPLY); \
BENCHMARK(NAME<absl::flat_hash_map<KT, VT>>)->Apply(APPLY); \
BENCHMARK(NAME<llvm::DenseMap<KT, VT>>)->Apply(APPLY); \
#define MAP_BENCHMARK_ONE_OP_SIZE(NAME, APPLY, KT, VT) \
BENCHMARK(NAME<Map<KT, VT>>)->Apply(APPLY); \
BENCHMARK(NAME<absl::flat_hash_map<KT, VT>>)->Apply(APPLY); \
BENCHMARK(NAME<boost::unordered::unordered_flat_map<KT, VT>>)->Apply(APPLY); \
BENCHMARK(NAME<llvm::DenseMap<KT, VT>>)->Apply(APPLY); \
BENCHMARK(NAME<llvm::DenseMap<KT, VT, CarbonHashDI<KT>>>)->Apply(APPLY)
// NOLINTEND(bugprone-macro-parentheses)
@@ -407,6 +414,8 @@ MAP_BENCHMARK_ONE_OP(BM_MapEraseUpdateHit, HitArgs);
#define MAP_BENCHMARK_OP_SEQ_SIZE(NAME, KT, VT) \
BENCHMARK(NAME<Map<KT, VT>>)->Apply(SizeArgs); \
BENCHMARK(NAME<absl::flat_hash_map<KT, VT>>)->Apply(SizeArgs); \
BENCHMARK(NAME<boost::unordered::unordered_flat_map<KT, VT>>) \
->Apply(SizeArgs); \
BENCHMARK(NAME<llvm::DenseMap<KT, VT>>)->Apply(APPLY); \
BENCHMARK(NAME<llvm::DenseMap<KT, VT, CarbonHashDI<KT>>>)->Apply(SizeArgs)
// NOLINTEND(bugprone-macro-parentheses)