Skip to content

Commit

Permalink
Add benchmark for encode and decode
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaimueller authored Sep 19, 2024
1 parent 5211bf6 commit 63c9231
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions benchmarks/util/Sharing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include "Util/Sharing.hpp"

#include <catch2/catch.hpp>

TEST_CASE("Benchmark the Boolean secret sharing",
"[Benchmark][BooleanSecretSharing]") {
boost::mt19937 rng;
boost::uniform_int<uint64_t> dist(0, std::numeric_limits<uint64_t>::max());
boost::variate_generator<boost::mt19937&, boost::uniform_int<uint64_t>> prng(
rng, dist);
std::vector<uint64_t> irreducible_polynomial = {1, 1};
Sharing sharing(2, 1, irreducible_polynomial, rng);

SECTION("Encode") {
std::vector<uint64_t> 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<uint64_t> bitsliced_element(1);
std::vector<std::vector<uint64_t>> 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<uint64_t> dist(0, std::numeric_limits<uint64_t>::max());
boost::variate_generator<boost::mt19937&, boost::uniform_int<uint64_t>> 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<uint64_t> 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<uint64_t> bitsliced_element(1);
std::vector<std::vector<uint64_t>> 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);
});
};
}
}

0 comments on commit 63c9231

Please sign in to comment.