Skip to content

Commit

Permalink
update experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqiNs committed Feb 20, 2025
1 parent 365c6c9 commit d86d6db
Show file tree
Hide file tree
Showing 7 changed files with 361 additions and 59 deletions.
14 changes: 7 additions & 7 deletions experiment/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -----------------------------------------------------
add_executable(SetupTime setup_time.cpp)
target_link_libraries(SetupTime PUBLIC EEJ)
# -----------------------------------------------------
add_executable(EncTime encryption_time.cpp)
target_link_libraries(EncTime PUBLIC EEJ)
# -----------------------------------------------------
# Grab all cpp file except the run.
file(GLOB SOURCES "*.cpp")
list(REMOVE_ITEM SOURCES "run.cpp")

# Add executable and link the library.
add_executable(EXP "run.cpp" ${SOURCES})
target_link_libraries(EXP PUBLIC EEJ)
58 changes: 29 additions & 29 deletions experiment/encryption_time.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#include <chrono>
#include <fstream>
#include "filter.hpp"
#include "ipe_filter.hpp"
#include "exp.hpp"

static int ROUND = 10;

void ipe_enc_time(){
void ipe_enc_time(const int round){
// Open the output files.
std::ofstream file("ipe_enc_time.txt", std::ios_base::app);
file << "IPE Enc Timings" << std::endl << std::endl;
std::ofstream file("enc_time.txt", std::ios_base::app);
file << "IPE Enc Timings" << std::endl;

for (int length = 10; length <= 200; length += 10){
// Create holder for timings.
Expand All @@ -19,9 +14,9 @@ void ipe_enc_time(){
auto msk = IpeFilter::msk_gen(pp);

// Perform ROUND number of Enc.
for (int i = 0; i < ROUND; ++i){
for (int i = 0; i < round; ++i){
// Create a random vector of desired length.
auto x = Helper::rand_int_vec(length, 1, 65536);
auto x = Helper::rand_int_vec(length, 1, std::numeric_limits<int>::max());

// Encryption timings.
auto start = std::chrono::high_resolution_clock::now();
Expand All @@ -31,16 +26,19 @@ void ipe_enc_time(){
}

// Output the time.
file << "(" << length << ", " << time.count() / ROUND << ")" << std::endl;
file << "(" << length << ", " << time.count() / round << ")" << std::endl;

// Close the BP.
BP::close();
}
// Create some blank spaces.
file << std::endl << std::endl;
}

void our_enc_time(){
void our_enc_time(const int round){
// Open the output files.
std::ofstream file("our_enc_time.txt", std::ios_base::app);
file << "Our Enc Timings" << std::endl << std::endl;
std::ofstream file("enc_time.txt", std::ios_base::app);
file << "Our Enc Timings" << std::endl;

for (int length = 10; length <= 200; length += 10){
// Create holder for timings.
Expand All @@ -51,9 +49,9 @@ void our_enc_time(){
auto msk = Filter::msk_gen(pp);

// Perform ROUND number of Enc.
for (int i = 0; i < ROUND; ++i){
for (int i = 0; i < round; ++i){
// Create a random vector of desired length.
auto x = Helper::rand_int_vec(length, 1, 65536);
auto x = Helper::rand_int_vec(length, 1, std::numeric_limits<int>::max());

// Encryption timings.
auto start = std::chrono::high_resolution_clock::now();
Expand All @@ -63,16 +61,19 @@ void our_enc_time(){
}

// Output the time.
file << "(" << length << ", " << time.count() / ROUND << ")" << std::endl;
file << "(" << length << ", " << time.count() / round << ")" << std::endl;

// Close the BP.
BP::close();
}
// Create some blank spaces.
file << std::endl << std::endl;
}

void sse_enc_time(){
void sse_enc_time(const int round){
// Open the output files.
std::ofstream file("sse_enc_time.txt", std::ios_base::app);
file << "SSE Enc Timings" << std::endl << std::endl;
std::ofstream file("enc_time.txt", std::ios_base::app);
file << "SSE Enc Timings" << std::endl;

// Setup and Encryption time.
for (int length = 10; length <= 200; length += 10){
Expand All @@ -83,9 +84,9 @@ void sse_enc_time(){
auto prf = PRF();

// Perform ROUND number of setup.
for (int i = 0; i < ROUND; ++i){
for (int i = 0; i < round; ++i){
// Create a random vector of desired length.
auto x = Helper::rand_int_vec(length, 1, 65536);
auto x = Helper::rand_int_vec(length, 1, std::numeric_limits<int>::max());

// Setup timings.
auto start = std::chrono::high_resolution_clock::now();
Expand All @@ -95,15 +96,14 @@ void sse_enc_time(){
}

// Output the time.
file << "(" << length << ", " << time.count() / ROUND << ")" << std::endl;
file << "(" << length << ", " << time.count() / round << ")" << std::endl;
}
// Create some blank spaces.
file << std::endl << std::endl;
}


int main(){
ipe_enc_time();
our_enc_time();
sse_enc_time();
void bench_enc_time(const int round){
ipe_enc_time(round);
our_enc_time(round);
sse_enc_time(round);
}
31 changes: 31 additions & 0 deletions experiment/exp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <limits>
#include <chrono>
#include <fstream>
#include "filter.hpp"
#include "ipe_filter.hpp"

/// Benchmark for setup.
void ipe_setup_time(int round);
void our_setup_time(int round);
void sse_setup_time(int round);
void bench_setup_time(int round);

/// Benchmark for encryption.
void ipe_enc_time(int round);
void our_enc_time(int round);
void sse_enc_time(int round);
void bench_enc_time(int round);

/// Benchmark for generating queries for filtering multiple rows.
void ipe_mul_row_time(int round);
void our_mul_row_time(int round);
void sse_mul_row_time(int round);
void bench_mul_row_time(int round);

/// Benchmark for generating single query while selecting different number of columns.
void ipe_sel_col_time(int round);
void our_sel_col_time(int round);
void sse_sel_col_time(int round);
void bench_sel_col_time(int round);
149 changes: 149 additions & 0 deletions experiment/multiple_row_time.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/// This file benchmarks when total length is 20 and selecting all columns, the cost of filtering n rows.
/// Note this is client query operation time, hence keygen is used.

#include "exp.hpp"

void ipe_mul_row_time(const int round){
// Open the output files.
std::ofstream time_file("multiple_row_time.txt", std::ios_base::app);
time_file << "IPE Row Timings" << std::endl;

std::ofstream storage_file("multiple_row_storage.txt", std::ios_base::app);
storage_file << "IPE Row Storage" << std::endl;

for (int num_row = 1; num_row <= 20; ++num_row){
// Create holder for timings.
std::chrono::duration<double, std::milli> time{};

// Create pp and msk.
auto pp = IpeFilter::pp_gen(1, 20);
auto msk = IpeFilter::msk_gen(pp);
G2Vec sk;

// Perform round number of Enc.
for (int i = 0; i < round; ++i){
// Create a random vector of desired length.
auto y = Helper::rand_int_mat(20, 1, 1, std::numeric_limits<int>::max());

// Encryption timings.
auto start = std::chrono::high_resolution_clock::now();
sk = IpeFilter::keygen(pp, msk, y);
auto end = std::chrono::high_resolution_clock::now();
time += end - start;
}

// Compute the sk size.
unsigned long sk_size = sk.size() * sizeof(uint8_t) * pp.pairing_group->Gp->g2_size;

// Output the time.
time_file << "(" << num_row << ", " << time.count() / round << ")" << std::endl;

// Output the storage.
storage_file << "(" << num_row << ", " << sk_size << ")" << std::endl;

// Close the BP.
BP::close();
}
// Create some blank spaces.
time_file << std::endl << std::endl;
storage_file << std::endl << std::endl;
}

void our_mul_row_time(const int round){
// Open the output files.
std::ofstream time_file("multiple_row_time.txt", std::ios_base::app);
time_file << "Our Row Timings" << std::endl;

std::ofstream storage_file("multiple_row_storage.txt", std::ios_base::app);
storage_file << "Our Row Storage" << std::endl;

for (int num_row = 1; num_row <= 20; ++num_row){
// Create holder for timings.
std::chrono::duration<double, std::milli> time{};

// Create pp and msk.
auto pp = Filter::pp_gen(1, 20);
auto msk = Filter::msk_gen(pp);
G2Vec sk;

// Perform round number of Enc.
for (int i = 0; i < round; ++i){
// Create a random vector of desired length.
auto y = Helper::rand_int_vec(20, 1, std::numeric_limits<int>::max());

// Encryption timings.
auto start = std::chrono::high_resolution_clock::now();
sk = Filter::keygen(pp, msk, y);
auto end = std::chrono::high_resolution_clock::now();
time += end - start;
}

// Compute the secret key size.
unsigned long sk_size = sk.size() * sizeof(uint8_t) * pp.pairing_group->Gp->g2_size;

// Output the time.
time_file << "(" << num_row << ", " << time.count() / round << ")" << std::endl;

// Output the storage.
storage_file << "(" << num_row << ", " << sk_size << ")" << std::endl;

// Close the BP.
BP::close();
}
// Create some blank spaces.
time_file << std::endl << std::endl;
storage_file << std::endl << std::endl;
}

void sse_mul_row_time(const int round){
// Open the output files.
std::ofstream time_file("multiple_row_time.txt", std::ios_base::app);
time_file << "SSE Row Timings" << std::endl;

std::ofstream storage_file("multiple_row_storage.txt", std::ios_base::app);
storage_file << "SSE Row Storage" << std::endl;

for (int num_row = 1; num_row <= 20; ++num_row){
// Create holder for timings.
std::chrono::duration<double, std::milli> time{};

// Compute the number of rows used.
int pow_row = static_cast<int>(std::pow(2, num_row));

// Create pp and msk.
auto prf = PRF();
CharVec sk;

// Perform ROUND number of setup.
for (int i = 0; i < round; ++i){
for (int j = 0; j < pow_row; ++j){
// Create a random vector of desired length.
auto y = Helper::rand_int_vec(20, 1, std::numeric_limits<int>::max());

// Enc timings.
auto start = std::chrono::high_resolution_clock::now();
for (const auto each_y : y) sk = prf.digest(Helper::int_to_char_vec(each_y));
auto end = std::chrono::high_resolution_clock::now();
time += end - start;
}
}

// Also create holder for size.
unsigned long sk_size = sk.size() * sizeof(unsigned char) * 20 * pow_row;

// Output the time.
time_file << "(" << num_row << ", " << time.count() / round << ")" << std::endl;

// Output the storage.
storage_file << "(" << num_row << ", " << sk_size << ")" << std::endl;
}
// Create some blank spaces.
time_file << std::endl << std::endl;
storage_file << std::endl << std::endl;
}

void bench_mul_row_time(const int round){
ipe_mul_row_time(round);
our_mul_row_time(round);
sse_mul_row_time(round);
}
9 changes: 9 additions & 0 deletions experiment/run.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "exp.hpp"

int main(){
// bench_setup_time(1);
// bench_enc_time(1);
bench_mul_row_time(1);

return 0;
}
Loading

0 comments on commit d86d6db

Please sign in to comment.