From 63c92310d83fb433a957040e9904091be31b8d49 Mon Sep 17 00:00:00 2001 From: Nicolai Mueller <97288834+nicolaimueller@users.noreply.github.com> Date: Thu, 19 Sep 2024 09:38:48 +0200 Subject: [PATCH] Add benchmark for encode and decode --- benchmarks/util/Sharing.cpp | 86 +++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 benchmarks/util/Sharing.cpp diff --git a/benchmarks/util/Sharing.cpp b/benchmarks/util/Sharing.cpp new file mode 100644 index 0000000..063b3d0 --- /dev/null +++ b/benchmarks/util/Sharing.cpp @@ -0,0 +1,86 @@ +#define CATCH_CONFIG_ENABLE_BENCHMARKING +#include "Util/Sharing.hpp" + +#include + +TEST_CASE("Benchmark the Boolean secret sharing", + "[Benchmark][BooleanSecretSharing]") { + boost::mt19937 rng; + boost::uniform_int dist(0, std::numeric_limits::max()); + boost::variate_generator> prng( + rng, dist); + std::vector irreducible_polynomial = {1, 1}; + Sharing sharing(2, 1, irreducible_polynomial, rng); + + SECTION("Encode") { + std::vector bitsliced_element(1); + uint64_t number_of_shares = GENERATE(1, 2, 3, 4, 5, 6, 7, 8); + bitsliced_element[0] = prng(); + + BENCHMARK_ADVANCED("number of shares (encode) = " + + std::to_string(number_of_shares)) + (Catch::Benchmark::Chronometer meter) { + meter.measure([&sharing, bitsliced_element, number_of_shares] { + sharing.EncodeBitsliced(bitsliced_element, number_of_shares, false); + }); + }; + } + + SECTION("Decode") { + std::vector bitsliced_element(1); + std::vector> bitsliced_shared_elements; + uint64_t number_of_shares = GENERATE(1, 2, 3, 4, 5, 6, 7, 8); + bitsliced_element[0] = prng(); + bitsliced_shared_elements = + sharing.EncodeBitsliced(bitsliced_element, number_of_shares, false); + + BENCHMARK_ADVANCED("number of shares (decode) = " + + std::to_string(number_of_shares)) + (Catch::Benchmark::Chronometer meter) { + meter.measure([&sharing, bitsliced_shared_elements] { + sharing.DecodeBitsliced(bitsliced_shared_elements, false); + }); + }; + } +} + +TEST_CASE("Benchmark the secret sharing in Rijndael field", + "[Benchmark][RijndaelFieldSharing]") { + boost::mt19937 rng; + boost::uniform_int dist(0, std::numeric_limits::max()); + boost::variate_generator> prng( + rng, dist); + Polynomial irreducible_polynomial = {1, 1, 0, 1, 1, 0, 0, 0, 1}; + Sharing sharing(2, 8, irreducible_polynomial, rng); + + SECTION("Encode") { + std::vector bitsliced_element(1); + uint64_t number_of_shares = GENERATE(1, 2, 3, 4, 5, 6, 7, 8); + bitsliced_element[0] = prng(); + + BENCHMARK_ADVANCED("number of shares (encode) = " + + std::to_string(number_of_shares)) + (Catch::Benchmark::Chronometer meter) { + meter.measure([&sharing, bitsliced_element, number_of_shares] { + sharing.EncodeBitsliced(bitsliced_element, number_of_shares, false); + }); + }; + } + + SECTION("Decode") { + std::vector bitsliced_element(1); + std::vector> bitsliced_shared_elements; + uint64_t number_of_shares = GENERATE(1, 2, 3, 4, 5, 6, 7, 8); + bitsliced_element[0] = prng(); + bitsliced_shared_elements = + sharing.EncodeBitsliced(bitsliced_element, number_of_shares, false); + + BENCHMARK_ADVANCED("number of shares (decode) = " + + std::to_string(number_of_shares)) + (Catch::Benchmark::Chronometer meter) { + meter.measure([&sharing, bitsliced_shared_elements] { + sharing.DecodeBitsliced(bitsliced_shared_elements, false); + }); + }; + } +} \ No newline at end of file