Compare commits

..

7 Commits

Author SHA1 Message Date
hashlag
1e593ef703 Merge branch 'sha1bench'
All checks were successful
Chaos Ci / test-and-benchmark (push) Successful in 2m9s
2026-01-25 19:17:51 +03:00
hashlag
9eb2a6bcde Add Sha1Hasher benchmarks 2026-01-25 19:17:16 +03:00
hashlag
85fe3cfe88 Refine benchmark names: use _ to highlight scope 2026-01-25 19:11:31 +03:00
hashlag
89991c21f5 Merge branch 'md5bench' 2026-01-25 19:09:17 +03:00
hashlag
d8c8fd0ce3 Add Md5Hasher benchmarks 2026-01-25 19:08:57 +03:00
hashlag
5ec6fc2f20 Add Md4HasherPartialUpdate100Bench 2026-01-25 18:55:51 +03:00
hashlag
512338df33 Add Md4HasherReuseBench 2026-01-25 18:45:38 +03:00
5 changed files with 184 additions and 14 deletions

View File

@@ -0,0 +1,3 @@
#include <benchmark/benchmark.h>
BENCHMARK_MAIN();

View File

@@ -12,7 +12,10 @@ 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)
set(ChaosBenches_SOURCE BenchmarkMain.cpp
Hash/Md4HasherBenches.cpp
Hash/Md5HasherBenches.cpp
Hash/Sha1HasherBenches.cpp)
add_executable(ChaosBenches ${ChaosBenches_SOURCE})
target_link_libraries(ChaosBenches benchmark::benchmark)

View File

@@ -5,27 +5,61 @@
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);
static const char * DATA_BEGIN
= "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.";
static const size_t DATA_LEN = strlen(DATA_BEGIN);
static const char * DATA_END = DATA_BEGIN + DATA_LEN;
static void Md4Hasher_CreateComputeDeleteBench(benchmark::State & state)
{
for (auto _ : state)
{
Md4Hasher hasher;
hasher.Update(data, data + dataLen);
hasher.Update(DATA_BEGIN, DATA_END);
Md4Hash result = hasher.Finish();
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(Md4HasherCreateComputeDeleteBench);
BENCHMARK(Md4Hasher_CreateComputeDeleteBench);
BENCHMARK_MAIN();
static void Md4Hasher_ReuseBench(benchmark::State & state)
{
Md4Hasher hasher;
for (auto _ : state)
{
hasher.Reset();
hasher.Update(DATA_BEGIN, DATA_END);
Md4Hash result = hasher.Finish();
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(Md4Hasher_ReuseBench);
static void Md4Hasher_PartialUpdate100Bench(benchmark::State & state)
{
for (auto _ : state)
{
Md4Hasher hasher;
for (int i = 0; i < 100; ++i)
{
hasher.Update(DATA_BEGIN, DATA_END);
}
Md4Hash result = hasher.Finish();
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(Md4Hasher_PartialUpdate100Bench);

View File

@@ -0,0 +1,65 @@
#include <benchmark/benchmark.h>
#include <cstring>
#include <Hash/Md5.hpp>
using namespace Chaos::Hash::Md5;
static const char * DATA_BEGIN
= "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.";
static const size_t DATA_LEN = strlen(DATA_BEGIN);
static const char * DATA_END = DATA_BEGIN + DATA_LEN;
static void Md5Hasher_CreateComputeDeleteBench(benchmark::State & state)
{
for (auto _ : state)
{
Md5Hasher hasher;
hasher.Update(DATA_BEGIN, DATA_END);
Md5Hash result = hasher.Finish();
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(Md5Hasher_CreateComputeDeleteBench);
static void Md5Hasher_ReuseBench(benchmark::State & state)
{
Md5Hasher hasher;
for (auto _ : state)
{
hasher.Reset();
hasher.Update(DATA_BEGIN, DATA_END);
Md5Hash result = hasher.Finish();
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(Md5Hasher_ReuseBench);
static void Md5Hasher_PartialUpdate100Bench(benchmark::State & state)
{
for (auto _ : state)
{
Md5Hasher hasher;
for (int i = 0; i < 100; ++i)
{
hasher.Update(DATA_BEGIN, DATA_END);
}
Md5Hash result = hasher.Finish();
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(Md5Hasher_PartialUpdate100Bench);

View File

@@ -0,0 +1,65 @@
#include <benchmark/benchmark.h>
#include <cstring>
#include <Hash/Sha1.hpp>
using namespace Chaos::Hash::Sha1;
static const char * DATA_BEGIN
= "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.";
static const size_t DATA_LEN = strlen(DATA_BEGIN);
static const char * DATA_END = DATA_BEGIN + DATA_LEN;
static void Sha1Hasher_CreateComputeDeleteBench(benchmark::State & state)
{
for (auto _ : state)
{
Sha1Hasher hasher;
hasher.Update(DATA_BEGIN, DATA_END);
Sha1Hash result = hasher.Finish();
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(Sha1Hasher_CreateComputeDeleteBench);
static void Sha1Hasher_ReuseBench(benchmark::State & state)
{
Sha1Hasher hasher;
for (auto _ : state)
{
hasher.Reset();
hasher.Update(DATA_BEGIN, DATA_END);
Sha1Hash result = hasher.Finish();
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(Sha1Hasher_ReuseBench);
static void Sha1Hasher_PartialUpdate100Bench(benchmark::State & state)
{
for (auto _ : state)
{
Sha1Hasher hasher;
for (int i = 0; i < 100; ++i)
{
hasher.Update(DATA_BEGIN, DATA_END);
}
Sha1Hash result = hasher.Finish();
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(Sha1Hasher_PartialUpdate100Bench);