diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ad3e34..c686d7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,3 +15,4 @@ target_include_directories(Chaos INTERFACE ) add_subdirectory(ChaosTests) +add_subdirectory(ChaosBenches) diff --git a/ChaosBenches/CMakeLists.txt b/ChaosBenches/CMakeLists.txt new file mode 100644 index 0000000..e058d00 --- /dev/null +++ b/ChaosBenches/CMakeLists.txt @@ -0,0 +1,21 @@ +include(FetchContent) + +cmake_policy(SET CMP0135 NEW) + +FetchContent_Declare( + googlebenchmark + URL https://github.com/google/benchmark/archive/refs/tags/v1.9.5.tar.gz + URL_HASH SHA256=9631341c82bac4a288bef951f8b26b41f69021794184ece969f8473977eaa340 +) + +set(BENCHMARK_ENABLE_WERROR OFF CACHE BOOL "" FORCE) +set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googlebenchmark) + +set(ChaosBenches_SOURCE Hash/Md4HasherBenches.cpp) + +add_executable(ChaosBenches ${ChaosBenches_SOURCE}) +target_link_libraries(ChaosBenches benchmark::benchmark) +target_include_directories(ChaosBenches PRIVATE + $ +) diff --git a/ChaosBenches/Hash/Md4HasherBenches.cpp b/ChaosBenches/Hash/Md4HasherBenches.cpp new file mode 100644 index 0000000..9c7a443 --- /dev/null +++ b/ChaosBenches/Hash/Md4HasherBenches.cpp @@ -0,0 +1,30 @@ +#include + +#include + +using namespace Chaos::Hash::Md4; + +static void Md4HasherCreateComputeDeleteBench(benchmark::State & state) +{ + const char * data + = "All states, all powers, that have held and hold rule over men have been and are either republics or principalities.\n" + "Principalities are either hereditary, in which the family has been long established; or they are new.\n" + "The new are either entirely new, as was Milan to Francesco Sforza, or they are, as it were, members annexed to the hereditary state of the " + "prince who has acquired them, as was the kingdom of Naples to that of the King of Spain.\n" + "Such dominions thus acquired are either accustomed to live under a prince, or to live in freedom; and are acquired either by the arms of the " + "prince himself, or of others, or else by fortune or by ability."; + const size_t dataLen = strlen(data); + + for (auto _ : state) + { + Md4Hasher hasher; + hasher.Update(data, data + dataLen); + Md4Hash result = hasher.Finish(); + + benchmark::DoNotOptimize(result); + } +} + +BENCHMARK(Md4HasherCreateComputeDeleteBench); + +BENCHMARK_MAIN();