diff --git a/include/ankerl/unordered_dense.h b/include/ankerl/unordered_dense.h index ab8c40e..e0168d0 100644 --- a/include/ankerl/unordered_dense.h +++ b/include/ankerl/unordered_dense.h @@ -334,7 +334,7 @@ struct tuple_hash_helper { // If it isn't an integral we need to hash it. template [[nodiscard]] constexpr static auto to64(Arg const& arg) -> uint64_t { - if constexpr (std::is_integral_v) { + if constexpr (std::is_integral_v || std::is_enum_v) { return static_cast(arg); } else { return hash{}(arg); diff --git a/scripts/build.py b/scripts/build.py index 25e0548..3b14985 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -7,10 +7,10 @@ cmd_and_dir = [ # needs honggfuzz installed - ['env', 'CXX_LD=mold', 'CXX=ccache g++', 'meson', 'setup', '--buildtype', 'release', '-Dcpp_std=c++17', 'builddir/gcc_cpp17_release'], + ['env', 'CXX_LD=mold', 'CXX=ccache clang++', 'meson', 'setup', '--buildtype', 'debug', '-Dcpp_std=c++17', 'builddir/clang_cpp17_debug'], ['env', 'CXX_LD=mold', 'CXX=ccache clang++', 'meson', 'setup', '--buildtype', 'release', '-Dcpp_std=c++17', 'builddir/clang_cpp17_release'], + ['env', 'CXX_LD=mold', 'CXX=ccache g++', 'meson', 'setup', '--buildtype', 'release', '-Dcpp_std=c++17', 'builddir/gcc_cpp17_release'], ['env', 'CXX_LD=mold', 'CXX=ccache hfuzz-clang++ -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', 'meson', 'setup', '--buildtype', 'release', '-Dcpp_std=c++17', 'builddir/hfuzz-clang_cpp17_release'], - ['env', 'CXX_LD=mold', 'CXX=ccache clang++', 'meson', 'setup', '--buildtype', 'debug', '-Dcpp_std=c++17', 'builddir/clang_cpp17_debug'], ['env', 'CXX_LD=mold', 'CXX=ccache g++', 'meson', 'setup', '--buildtype', 'debug', '-Dcpp_std=c++17', 'builddir/gcc_cpp17_debug'], # 32bit. Install lib32-clang diff --git a/test/unit/tuple_hash.cpp b/test/unit/tuple_hash.cpp index 2172caa..104cfe8 100644 --- a/test/unit/tuple_hash.cpp +++ b/test/unit/tuple_hash.cpp @@ -45,13 +45,26 @@ TEST_CASE("tuple_hash_with_stringview") { REQUIRE(h1 != h2); } +// #include + TEST_CASE("bench_tuple_hash" * doctest::test_suite("bench")) { - using T = std::tuple; + using T = std::tuple; + + auto vecs = std::vector(100); + auto rng = ankerl::nanobench::Rng(123); + for (auto& v : vecs) { + std::get<0>(v) = static_cast(rng()); + std::get<1>(v) = static_cast(rng()); + std::get<2>(v) = static_cast(rng()); + std::get<3>(v) = static_cast(rng()); + } - auto h = uint64_t{}; - auto t = std::tuple{}; - ankerl::nanobench::Bench().run("ankerl hash", [&] { - h += ankerl::unordered_dense::hash{}(t); - ++std::get<4>(t); + uint64_t h = 0; + ankerl::nanobench::Bench().batch(vecs.size()).run("ankerl hash", [&] { + for (auto const& v : vecs) { + h += ankerl::unordered_dense::hash{}(v); + // h += absl::Hash{}(v); + } }); + ankerl::nanobench::doNotOptimizeAway(h); }