This commit is contained in:
JCW
2025-06-02 16:43:00 +01:00
parent 0b29ff0bf7
commit 3e13bd036e

View File

@@ -32,6 +32,7 @@
#include <span> #include <span>
#include <type_traits> #include <type_traits>
#define ORIGINAL_HASH 1
#define BIT_SHIFT_HASH 0 #define BIT_SHIFT_HASH 0
namespace beast { namespace beast {
@@ -45,7 +46,10 @@ private:
// requires 64-bit std::size_t // requires 64-bit std::size_t
static_assert(sizeof(std::size_t) == 8, ""); static_assert(sizeof(std::size_t) == 8, "");
// XXH3_state_t* state_; #if ORIGINAL_HASH
XXH3_state_t* state_;
#endif
#if PROFILING #if PROFILING
std::size_t totalSize_ = 0; std::size_t totalSize_ = 0;
std::chrono::nanoseconds duration_{}; std::chrono::nanoseconds duration_{};
@@ -57,15 +61,16 @@ private:
std::span<std::uint8_t> readBuffer_; std::span<std::uint8_t> readBuffer_;
std::span<std::uint8_t> writeBuffer_; std::span<std::uint8_t> writeBuffer_;
// static XXH3_state_t* #if ORIGINAL_HASH
// allocState() static XXH3_state_t*
// { allocState()
// FunctionProfiler _{"-alloc"}; {
// auto ret = XXH3_createState(); auto ret = XXH3_createState();
// if (ret == nullptr) if (ret == nullptr)
// throw std::bad_alloc(); throw std::bad_alloc();
// return ret; return ret;
// } }
#endif
void void
setupBuffers() setupBuffers()
@@ -95,27 +100,24 @@ public:
xxhasher() xxhasher()
{ {
#if ORIGINAL_HASH
auto start = std::chrono::steady_clock::now();
auto cpuCyclesStart = __rdtsc();
state_ = allocState();
XXH3_64bits_reset(state_);
duration_ += std::chrono::steady_clock::now() - start;
cpuCycles += (__rdtsc() - cpuCyclesStart);
#else
setupBuffers(); setupBuffers();
// auto start = std::chrono::steady_clock::now(); #endif
// auto cpuCyclesStart = __rdtsc();
// // state_ = allocState();
// // XXH3_64bits_reset(state_);
// XXH3_64bits_reset(wrapper.state);
// duration_ += std::chrono::steady_clock::now() - start;
// cpuCycles += (__rdtsc() - cpuCyclesStart);
} }
// ~xxhasher() noexcept #if ORIGINAL_HASH
// { ~xxhasher() noexcept
// // profiler_.functionName = "xxhasher-" + std::to_string(totalSize_); {
// // auto start = std::chrono::steady_clock::now(); XXH3_freeState(state_);
// if (0) }
// { #endif
// FunctionProfiler _{"-free"};
// XXH3_freeState(state_);
// }
// }
template < template <
class Seed, class Seed,
std::enable_if_t<std::is_unsigned<Seed>::value>* = nullptr> std::enable_if_t<std::is_unsigned<Seed>::value>* = nullptr>
@@ -123,15 +125,17 @@ public:
{ {
seed_ = seed; seed_ = seed;
setupBuffers();
// auto start = std::chrono::steady_clock::now(); #if ORIGINAL_HASH
// auto cpuCyclesStart = __rdtsc(); auto start = std::chrono::steady_clock::now();
// state_ = allocState(); auto cpuCyclesStart = __rdtsc();
// XXH3_64bits_reset_withSeed(state_, seed); state_ = allocState();
// XXH3_64bits_reset_withSeed(wrapper.state, seed); XXH3_64bits_reset_withSeed(state_, seed);
// duration_ += std::chrono::steady_clock::now() - start; duration_ += std::chrono::steady_clock::now() - start;
// cpuCycles += (__rdtsc() - cpuCyclesStart); cpuCycles += (__rdtsc() - cpuCyclesStart);
#else
setupBuffers();
#endif
} }
template < template <
@@ -141,14 +145,16 @@ public:
{ {
seed_ = seed; seed_ = seed;
#if ORIGINAL_HASH
auto start = std::chrono::steady_clock::now();
auto cpuCyclesStart = __rdtsc();
state_ = allocState();
XXH3_64bits_reset_withSeed(state_, seed);
duration_ += std::chrono::steady_clock::now() - start;
cpuCycles += (__rdtsc() - cpuCyclesStart);
#else
setupBuffers(); setupBuffers();
// auto start = std::chrono::steady_clock::now(); #endif
// auto cpuCyclesStart = __rdtsc();
// // state_ = allocState();
// // XXH3_64bits_reset_withSeed(state_, seed);
// XXH3_64bits_reset_withSeed(wrapper.state, seed);
// duration_ += std::chrono::steady_clock::now() - start;
// cpuCycles += (__rdtsc() - cpuCyclesStart);
} }
void void
@@ -159,11 +165,11 @@ public:
auto start = std::chrono::steady_clock::now(); auto start = std::chrono::steady_clock::now();
auto cpuCyclesStart = __rdtsc(); auto cpuCyclesStart = __rdtsc();
#endif #endif
// FunctionProfiler _{"-size-" + std::to_string(len)}; #if ORIGINAL_HASH
// XXH3_64bits_update(state_, key, len); XXH3_64bits_update(state_, key, len);
// XXH3_64bits_update(wrapper.state, key, len); #else
writeBuffer(key, len); writeBuffer(key, len);
#endif
#if PROFILING #if PROFILING
duration_ += std::chrono::steady_clock::now() - start; duration_ += std::chrono::steady_clock::now() - start;