mirror of https://github.com/dnomd343/md5sum.git
Dnomd343
8 months ago
1 changed files with 26 additions and 17 deletions
@ -1,34 +1,43 @@ |
|||||
#include <benchmark/benchmark.h> |
|
||||
|
|
||||
#include "md5.h" |
#include "md5.h" |
||||
|
#include "benchmark/benchmark.h" |
||||
|
|
||||
|
using md5::MD5; |
||||
|
|
||||
std::string test_data() { |
std::string build_test_data() { |
||||
char data[64]; |
std::string data(65536, 0x00); |
||||
for (char i = 0; i < 64; ++i) { |
for (uint32_t i = 0; i < data.size(); ++i) { |
||||
data[i] = i; |
data[i] = static_cast<char>(i & 0xff); |
||||
} |
} |
||||
return {data, data + 64}; |
return data; |
||||
} |
} |
||||
|
|
||||
static void MD5_Update(benchmark::State &state) { |
static void MD5_Digest(benchmark::State &state) { |
||||
const auto data = test_data(); |
MD5 md5; |
||||
|
|
||||
md5::MD5 kk; |
|
||||
|
|
||||
for (auto _ : state) { |
for (auto _ : state) { |
||||
kk.Update(data.c_str(), 64); |
auto volatile holder = md5.Digest(); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
static void MD5_Digest(benchmark::State &state) { |
static void MD5_Update(benchmark::State &state) { |
||||
md5::MD5 kk; |
MD5 md5; |
||||
|
const auto data = build_test_data(); |
||||
for (auto _ : state) { |
for (auto _ : state) { |
||||
auto pp = kk.Digest(); |
md5.Update(data.c_str(), state.range(0)); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
BENCHMARK(MD5_Update); |
static void MD5_Hash(benchmark::State &state) { |
||||
|
const auto data = build_test_data(); |
||||
|
for (auto _ : state) { |
||||
|
MD5::Hash(data.c_str(), state.range(0)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
BENCHMARK(MD5_Digest); |
BENCHMARK(MD5_Digest); |
||||
|
|
||||
|
BENCHMARK(MD5_Update)->RangeMultiplier(4)->Range(64, 4096); |
||||
|
|
||||
|
BENCHMARK(MD5_Hash)->Arg(0); |
||||
|
BENCHMARK(MD5_Hash)->RangeMultiplier(4)->Range(64, 4096); |
||||
|
|
||||
BENCHMARK_MAIN(); |
BENCHMARK_MAIN(); |
||||
|
Loading…
Reference in new issue