Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: test(-bench) housekeeping #375

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/test-bench.cpp
Expand Up @@ -21,18 +21,16 @@ extern "C" {
}

using std::string;
using std::vector;
using std::cout;
using std::endl;

using namespace bls;

typedef std::vector<uint8_t> bytevec_t;

void benchSigs() {
string testName = "Signing";
const int numIters = 5000;
PrivateKey sk = AugSchemeMPL().KeyGen(getRandomSeed());
vector<uint8_t> message1 = sk.GetG1Element().Serialize();
bytevec_t message1 = sk.GetG1Element().Serialize();

auto start = startStopwatch();

Expand All @@ -53,15 +51,15 @@ void benchVerification() {
for (int i = 0; i < numIters; i++) {
uint8_t message[4];
Util::IntToFourBytes(message, i);
vector<uint8_t> messageBytes(message, message + 4);
bytevec_t messageBytes(message, message + 4);
sigs.push_back(AugSchemeMPL().Sign(sk, messageBytes));
}

auto start = startStopwatch();
for (int i = 0; i < numIters; i++) {
uint8_t message[4];
Util::IntToFourBytes(message, i);
vector<uint8_t> messageBytes(message, message + 4);
bytevec_t messageBytes(message, message + 4);
bool ok = AugSchemeMPL().Verify(pk, messageBytes, sigs[i]);
ASSERT(ok);
}
Expand All @@ -71,22 +69,22 @@ void benchVerification() {
void benchBatchVerification() {
const int numIters = 100000;

vector<vector<uint8_t>> sig_bytes;
vector<vector<uint8_t>> pk_bytes;
vector<vector<uint8_t>> ms;
std::vector<bytevec_t> sig_bytes;
std::vector<bytevec_t> pk_bytes;
std::vector<bytevec_t> ms;

for (int i = 0; i < numIters; i++) {
uint8_t message[4];
Util::IntToFourBytes(message, i);
vector<uint8_t> messageBytes(message, message + 4);
bytevec_t messageBytes(message, message + 4);
PrivateKey sk = AugSchemeMPL().KeyGen(getRandomSeed());
G1Element pk = sk.GetG1Element();
sig_bytes.push_back(AugSchemeMPL().Sign(sk, messageBytes).Serialize());
pk_bytes.push_back(pk.Serialize());
ms.push_back(messageBytes);
}

vector<G1Element> pks;
std::vector<G1Element> pks;
pks.reserve(numIters);

auto start = startStopwatch();
Expand All @@ -95,7 +93,7 @@ void benchBatchVerification() {
}
endStopwatch("Public key validation", start, numIters);

vector<G2Element> sigs;
std::vector<G2Element> sigs;
sigs.reserve(numIters);

start = startStopwatch();
Expand All @@ -117,10 +115,10 @@ void benchBatchVerification() {
void benchFastAggregateVerification() {
const int numIters = 5000;

vector<G2Element> sigs;
vector<G1Element> pks;
vector<uint8_t> message = {1, 2, 3, 4, 5, 6, 7, 8};
vector<G2Element> pops;
std::vector<G2Element> sigs;
std::vector<G1Element> pks;
bytevec_t message{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
std::vector<G2Element> pops;

for (int i = 0; i < numIters; i++) {
PrivateKey sk = PopSchemeMPL().KeyGen(getRandomSeed());
Expand Down