Skip to content

Commit

Permalink
benchmark minimum and maximum execution time of functions
Browse files Browse the repository at this point in the history
Signed-off-by: Anjan Roy <[email protected]>
  • Loading branch information
itzmeanjan committed Dec 22, 2023
1 parent 2022f4e commit 7c91228
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
12 changes: 12 additions & 0 deletions benchmarks/bench_common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <algorithm>
#include <vector>

const auto compute_min = [](const std::vector<double>& v) -> double {
return *std::min_element(v.begin(), v.end());
};

const auto compute_max = [](const std::vector<double>& v) -> double {
return *std::max_element(v.begin(), v.end());
};
18 changes: 13 additions & 5 deletions benchmarks/bench_hashing.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "bench_common.hpp"
#include "sha3_224.hpp"
#include "sha3_256.hpp"
#include "sha3_384.hpp"
#include "sha3_512.hpp"
#include <benchmark/benchmark.h>
#include <vector>

// Benchmarks SHA3-224 hash function with variable length input message.
void
Expand Down Expand Up @@ -136,16 +136,24 @@ bench_sha3_512(benchmark::State& state)
BENCHMARK(bench_sha3_224)
->RangeMultiplier(4)
->Range(64, 16384)
->Name("sha3_224");
->Name("sha3_224")
->ComputeStatistics("min", compute_min)
->ComputeStatistics("max", compute_max);
BENCHMARK(bench_sha3_256)
->RangeMultiplier(4)
->Range(64, 16384)
->Name("sha3_256");
->Name("sha3_256")
->ComputeStatistics("min", compute_min)
->ComputeStatistics("max", compute_max);
BENCHMARK(bench_sha3_384)
->RangeMultiplier(4)
->Range(64, 16384)
->Name("sha3_384");
->Name("sha3_384")
->ComputeStatistics("min", compute_min)
->ComputeStatistics("max", compute_max);
BENCHMARK(bench_sha3_512)
->RangeMultiplier(4)
->Range(64, 16384)
->Name("sha3_512");
->Name("sha3_512")
->ComputeStatistics("min", compute_min)
->ComputeStatistics("max", compute_max);
6 changes: 5 additions & 1 deletion benchmarks/bench_keccak.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "bench_common.hpp"
#include "keccak.hpp"
#include "utils.hpp"
#include <benchmark/benchmark.h>
Expand All @@ -24,4 +25,7 @@ bench_keccak_permutation(benchmark::State& state)
#endif
}

BENCHMARK(bench_keccak_permutation)->Name("keccak-p[1600, 24]");
BENCHMARK(bench_keccak_permutation)
->Name("keccak-p[1600, 24]")
->ComputeStatistics("min", compute_min)
->ComputeStatistics("max", compute_max);
10 changes: 7 additions & 3 deletions benchmarks/bench_xof.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "bench_common.hpp"
#include "shake128.hpp"
#include "shake256.hpp"
#include <benchmark/benchmark.h>
#include <vector>

// Benchmarks SHAKE-128 extendable output function with variable length input
// and squeezed output.
Expand Down Expand Up @@ -77,7 +77,11 @@ bench_shake256(benchmark::State& state)

BENCHMARK(bench_shake128)
->ArgsProduct({ benchmark::CreateRange(64, 16384, 4), { 64 } })
->Name("shake128");
->Name("shake128")
->ComputeStatistics("min", compute_min)
->ComputeStatistics("max", compute_max);
BENCHMARK(bench_shake256)
->ArgsProduct({ benchmark::CreateRange(64, 16384, 4), { 64 } })
->Name("shake256");
->Name("shake256")
->ComputeStatistics("min", compute_min)
->ComputeStatistics("max", compute_max);

0 comments on commit 7c91228

Please sign in to comment.