Compare commits
11 Commits
11561c9379
...
2c9200ab21
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c9200ab21 | ||
|
|
6246bf4538 | ||
|
|
78c59dc668 | ||
|
|
d4fa11795b | ||
|
|
3780586e63 | ||
|
|
cc9963f1ca | ||
|
|
05533e7c6b | ||
|
|
961a521c57 | ||
|
|
029055f9a3 | ||
|
|
b5f86b5633 | ||
|
|
0bc29c86e5 |
@@ -15,7 +15,8 @@ FetchContent_MakeAvailable(googlebenchmark)
|
|||||||
set(ChaosBenches_SOURCE BenchmarkMain.cpp
|
set(ChaosBenches_SOURCE BenchmarkMain.cpp
|
||||||
Hash/Md4HasherBenches.cpp
|
Hash/Md4HasherBenches.cpp
|
||||||
Hash/Md5HasherBenches.cpp
|
Hash/Md5HasherBenches.cpp
|
||||||
Hash/Sha1HasherBenches.cpp)
|
Hash/Sha1HasherBenches.cpp
|
||||||
|
Mac/HmacBenches.cpp)
|
||||||
|
|
||||||
add_executable(ChaosBenches ${ChaosBenches_SOURCE})
|
add_executable(ChaosBenches ${ChaosBenches_SOURCE})
|
||||||
target_link_libraries(ChaosBenches benchmark::benchmark)
|
target_link_libraries(ChaosBenches benchmark::benchmark)
|
||||||
|
|||||||
173
ChaosBenches/Mac/HmacBenches.cpp
Normal file
173
ChaosBenches/Mac/HmacBenches.cpp
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
#include <benchmark/benchmark.h>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "Mac/Hmac.hpp"
|
||||||
|
#include "Hash/Md4.hpp"
|
||||||
|
#include "Hash/Md5.hpp"
|
||||||
|
#include "Hash/Sha1.hpp"
|
||||||
|
|
||||||
|
using namespace Chaos::Mac::Hmac;
|
||||||
|
using namespace Chaos::Hash::Md4;
|
||||||
|
using namespace Chaos::Hash::Md5;
|
||||||
|
using namespace Chaos::Hash::Sha1;
|
||||||
|
|
||||||
|
static const char * KEY_BEGIN = "Niccolo01234567";
|
||||||
|
static const size_t KEY_LEN = strlen(KEY_BEGIN);
|
||||||
|
static const char * KEY_END = KEY_BEGIN + KEY_LEN;
|
||||||
|
|
||||||
|
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 HmacMd4_CreateComputeDeleteBench(benchmark::State & state)
|
||||||
|
{
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
Hmac<Md4Hasher> hmac(KEY_BEGIN, KEY_END);
|
||||||
|
hmac.Update(DATA_BEGIN, DATA_END);
|
||||||
|
Md4Hash result = hmac.Finish();
|
||||||
|
|
||||||
|
benchmark::DoNotOptimize(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(HmacMd4_CreateComputeDeleteBench);
|
||||||
|
|
||||||
|
static void HmacMd4_ReuseBench(benchmark::State & state)
|
||||||
|
{
|
||||||
|
Hmac<Md4Hasher> hmac;
|
||||||
|
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
hmac.Rekey(KEY_BEGIN, KEY_END);
|
||||||
|
hmac.Update(DATA_BEGIN, DATA_END);
|
||||||
|
Md4Hash result = hmac.Finish();
|
||||||
|
|
||||||
|
benchmark::DoNotOptimize(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(HmacMd4_ReuseBench);
|
||||||
|
|
||||||
|
static void HmacMd4_PartialUpdate100Bench(benchmark::State & state)
|
||||||
|
{
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
Hmac<Md4Hasher> hmac(KEY_BEGIN, KEY_END);
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; ++i)
|
||||||
|
{
|
||||||
|
hmac.Update(DATA_BEGIN, DATA_END);
|
||||||
|
}
|
||||||
|
|
||||||
|
Md4Hash result = hmac.Finish();
|
||||||
|
|
||||||
|
benchmark::DoNotOptimize(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(HmacMd4_PartialUpdate100Bench);
|
||||||
|
|
||||||
|
static void HmacMd5_CreateComputeDeleteBench(benchmark::State & state)
|
||||||
|
{
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
Hmac<Md5Hasher> hmac(KEY_BEGIN, KEY_END);
|
||||||
|
hmac.Update(DATA_BEGIN, DATA_END);
|
||||||
|
Md5Hash result = hmac.Finish();
|
||||||
|
|
||||||
|
benchmark::DoNotOptimize(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(HmacMd5_CreateComputeDeleteBench);
|
||||||
|
|
||||||
|
static void HmacMd5_ReuseBench(benchmark::State & state)
|
||||||
|
{
|
||||||
|
Hmac<Md5Hasher> hmac;
|
||||||
|
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
hmac.Rekey(KEY_BEGIN, KEY_END);
|
||||||
|
hmac.Update(DATA_BEGIN, DATA_END);
|
||||||
|
Md5Hash result = hmac.Finish();
|
||||||
|
|
||||||
|
benchmark::DoNotOptimize(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(HmacMd5_ReuseBench);
|
||||||
|
|
||||||
|
static void HmacMd5_PartialUpdate100Bench(benchmark::State & state)
|
||||||
|
{
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
Hmac<Md5Hasher> hmac(KEY_BEGIN, KEY_END);
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; ++i)
|
||||||
|
{
|
||||||
|
hmac.Update(DATA_BEGIN, DATA_END);
|
||||||
|
}
|
||||||
|
|
||||||
|
Md5Hash result = hmac.Finish();
|
||||||
|
|
||||||
|
benchmark::DoNotOptimize(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(HmacMd5_PartialUpdate100Bench);
|
||||||
|
|
||||||
|
static void HmacSha1_CreateComputeDeleteBench(benchmark::State & state)
|
||||||
|
{
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
Hmac<Sha1Hasher> hmac(KEY_BEGIN, KEY_END);
|
||||||
|
hmac.Update(DATA_BEGIN, DATA_END);
|
||||||
|
Sha1Hash result = hmac.Finish();
|
||||||
|
|
||||||
|
benchmark::DoNotOptimize(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(HmacSha1_CreateComputeDeleteBench);
|
||||||
|
|
||||||
|
static void HmacSha1_ReuseBench(benchmark::State & state)
|
||||||
|
{
|
||||||
|
Hmac<Sha1Hasher> hmac;
|
||||||
|
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
hmac.Rekey(KEY_BEGIN, KEY_END);
|
||||||
|
hmac.Update(DATA_BEGIN, DATA_END);
|
||||||
|
Sha1Hash result = hmac.Finish();
|
||||||
|
|
||||||
|
benchmark::DoNotOptimize(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(HmacSha1_ReuseBench);
|
||||||
|
|
||||||
|
static void HmacSha1_PartialUpdate100Bench(benchmark::State & state)
|
||||||
|
{
|
||||||
|
for (auto _ : state)
|
||||||
|
{
|
||||||
|
Hmac<Sha1Hasher> hmac(KEY_BEGIN, KEY_END);
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; ++i)
|
||||||
|
{
|
||||||
|
hmac.Update(DATA_BEGIN, DATA_END);
|
||||||
|
}
|
||||||
|
|
||||||
|
Sha1Hash result = hmac.Finish();
|
||||||
|
|
||||||
|
benchmark::DoNotOptimize(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK(HmacSha1_PartialUpdate100Bench);
|
||||||
Reference in New Issue
Block a user