Skip to content

Commit

Permalink
Refactor benchmark functions to make them easier to grasp
Browse files Browse the repository at this point in the history
Signed-off-by: Anjan Roy <[email protected]>
  • Loading branch information
itzmeanjan committed Oct 22, 2024
1 parent 220c2e8 commit 02d848e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
7 changes: 5 additions & 2 deletions benches/bench_client_prepare_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ template<size_t λ, size_t db_entry_count, size_t db_entry_byte_len, size_t mat_
static void
bench_client_prepare_query(benchmark::State& state)
{
using server_t = frodoPIR_server::server_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>;
using client_t = frodoPIR_client::client_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>;

constexpr size_t db_byte_len = db_entry_count * db_entry_byte_len;
constexpr size_t parsed_db_column_count = frodoPIR_matrix::get_required_num_columns(db_entry_byte_len, mat_element_bitlen);
constexpr size_t pub_matM_byte_len = frodoPIR_matrix::matrix_t<lwe_dimension, parsed_db_column_count>::get_byte_len();
Expand All @@ -33,10 +36,10 @@ bench_client_prepare_query(benchmark::State& state)
prng.read(seed_μ_span);
prng.read(db_bytes_span);

auto [server, M] = frodoPIR_server::server_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>::setup(seed_μ_span, db_bytes_span);
auto [server, M] = server_t::setup(seed_μ_span, db_bytes_span);

M.to_le_bytes(pub_matM_bytes_span);
auto client = frodoPIR_client::client_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>::setup(seed_μ, pub_matM_bytes_span);
auto client = client_t::setup(seed_μ, pub_matM_bytes_span);

size_t rand_db_row_index = [&]() {
size_t buffer = 0;
Expand Down
7 changes: 5 additions & 2 deletions benches/bench_client_process_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ template<size_t λ, size_t db_entry_count, size_t db_entry_byte_len, size_t mat_
static void
bench_client_process_response(benchmark::State& state)
{
using server_t = frodoPIR_server::server_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>;
using client_t = frodoPIR_client::client_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>;

constexpr size_t db_byte_len = db_entry_count * db_entry_byte_len;
constexpr size_t parsed_db_column_count = frodoPIR_matrix::get_required_num_columns(db_entry_byte_len, mat_element_bitlen);
constexpr size_t pub_matM_byte_len = frodoPIR_matrix::matrix_t<lwe_dimension, parsed_db_column_count>::get_byte_len();
Expand All @@ -33,10 +36,10 @@ bench_client_process_response(benchmark::State& state)
prng.read(seed_μ_span);
prng.read(db_bytes_span);

auto [server, M] = frodoPIR_server::server_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>::setup(seed_μ_span, db_bytes_span);
auto [server, M] = server_t::setup(seed_μ_span, db_bytes_span);

M.to_le_bytes(pub_matM_bytes_span);
auto client = frodoPIR_client::client_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>::setup(seed_μ, pub_matM_bytes_span);
auto client = client_t::setup(seed_μ, pub_matM_bytes_span);

size_t rand_db_row_index = [&]() {
size_t buffer = 0;
Expand Down
7 changes: 5 additions & 2 deletions benches/bench_client_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ template<size_t λ, size_t db_entry_count, size_t db_entry_byte_len, size_t mat_
static void
bench_client_query(benchmark::State& state)
{
using server_t = frodoPIR_server::server_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>;
using client_t = frodoPIR_client::client_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>;

constexpr size_t db_byte_len = db_entry_count * db_entry_byte_len;
constexpr size_t parsed_db_column_count = frodoPIR_matrix::get_required_num_columns(db_entry_byte_len, mat_element_bitlen);
constexpr size_t pub_matM_byte_len = frodoPIR_matrix::matrix_t<lwe_dimension, parsed_db_column_count>::get_byte_len();
Expand All @@ -33,10 +36,10 @@ bench_client_query(benchmark::State& state)
prng.read(seed_μ_span);
prng.read(db_bytes_span);

auto [server, M] = frodoPIR_server::server_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>::setup(seed_μ_span, db_bytes_span);
auto [server, M] = server_t::setup(seed_μ_span, db_bytes_span);

M.to_le_bytes(pub_matM_bytes_span);
auto client = frodoPIR_client::client_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>::setup(seed_μ, pub_matM_bytes_span);
auto client = client_t::setup(seed_μ, pub_matM_bytes_span);

size_t rand_db_row_index = [&]() {
size_t buffer = 0;
Expand Down
7 changes: 5 additions & 2 deletions benches/bench_client_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ template<size_t λ, size_t db_entry_count, size_t db_entry_byte_len, size_t mat_
static void
bench_client_setup(benchmark::State& state)
{
using server_t = frodoPIR_server::server_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>;
using client_t = frodoPIR_client::client_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>;

constexpr size_t db_byte_len = db_entry_count * db_entry_byte_len;
constexpr size_t parsed_db_column_count = frodoPIR_matrix::get_required_num_columns(db_entry_byte_len, mat_element_bitlen);
constexpr size_t pub_matM_byte_len = frodoPIR_matrix::matrix_t<lwe_dimension, parsed_db_column_count>::get_byte_len();
Expand All @@ -25,12 +28,12 @@ bench_client_setup(benchmark::State& state)
prng.read(seed_μ_span);
prng.read(db_bytes_span);

auto [server, M] = frodoPIR_server::server_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>::setup(seed_μ_span, db_bytes_span);
auto [server, M] = server_t::setup(seed_μ_span, db_bytes_span);

M.to_le_bytes(pub_matM_bytes_span);

for (auto _ : state) {
auto client = frodoPIR_client::client_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>::setup(seed_μ, pub_matM_bytes_span);
auto client = client_t::setup(seed_μ, pub_matM_bytes_span);

benchmark::DoNotOptimize(client);
benchmark::DoNotOptimize(seed_μ);
Expand Down
7 changes: 5 additions & 2 deletions benches/bench_server_respond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ template<size_t λ, size_t db_entry_count, size_t db_entry_byte_len, size_t mat_
static void
bench_server_respond(benchmark::State& state)
{
using server_t = frodoPIR_server::server_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>;
using client_t = frodoPIR_client::client_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>;

constexpr size_t db_byte_len = db_entry_count * db_entry_byte_len;
constexpr size_t parsed_db_column_count = frodoPIR_matrix::get_required_num_columns(db_entry_byte_len, mat_element_bitlen);
constexpr size_t pub_matM_byte_len = frodoPIR_matrix::matrix_t<lwe_dimension, parsed_db_column_count>::get_byte_len();
Expand All @@ -31,10 +34,10 @@ bench_server_respond(benchmark::State& state)
prng.read(seed_μ_span);
prng.read(db_bytes_span);

auto [server, M] = frodoPIR_server::server_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>::setup(seed_μ_span, db_bytes_span);
auto [server, M] = server_t::setup(seed_μ_span, db_bytes_span);

M.to_le_bytes(pub_matM_bytes_span);
auto client = frodoPIR_client::client_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>::setup(seed_μ, pub_matM_bytes_span);
auto client = client_t::setup(seed_μ, pub_matM_bytes_span);

const size_t rand_db_row_index = [&]() {
size_t buffer = 0;
Expand Down
4 changes: 3 additions & 1 deletion benches/bench_server_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ template<size_t λ, size_t db_entry_count, size_t db_entry_byte_len, size_t mat_
static void
bench_server_setup(benchmark::State& state)
{
using server_t = frodoPIR_server::server_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>;

constexpr size_t db_byte_len = db_entry_count * db_entry_byte_len;

std::array<uint8_t, λ / std::numeric_limits<uint8_t>::digits> seed_μ{};
Expand All @@ -20,7 +22,7 @@ bench_server_setup(benchmark::State& state)
prng.read(db_bytes_span);

for (auto _ : state) {
auto [server, M] = frodoPIR_server::server_t<λ, db_entry_count, db_entry_byte_len, mat_element_bitlen, lwe_dimension>::setup(seed_μ_span, db_bytes_span);
auto [server, M] = server_t::setup(seed_μ_span, db_bytes_span);

benchmark::DoNotOptimize(seed_μ_span);
benchmark::DoNotOptimize(db_bytes_span);
Expand Down

0 comments on commit 02d848e

Please sign in to comment.