Skip to content

Commit 61bba13

Browse files
UdjinM6kwvg
authored andcommitted
fix: tweak bls/bls_dkg benchmarks to work faster in -sanity-check mode
1 parent 0eff28c commit 61bba13

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

src/bench/bls.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void BLS_PubKeyAggregate_Normal(benchmark::Bench& bench)
4949
CBLSPublicKey pubKey2 = secKey2.GetPublicKey();
5050

5151
// Benchmark.
52-
bench.minEpochIterations(100).run([&] {
52+
bench.minEpochIterations(bench.output() ? 100 : 1).run([&] {
5353
pubKey1.AggregateInsecure(pubKey2);
5454
});
5555
}
@@ -126,10 +126,10 @@ static void BLS_Verify_LargeBlock(size_t txCount, benchmark::Bench& bench, uint3
126126
std::vector<CBLSSignature> sigs;
127127
std::vector<uint256> msgHashes;
128128
std::vector<bool> invalid;
129-
BuildTestVectors(txCount, 0, pubKeys, secKeys, sigs, msgHashes, invalid);
129+
BuildTestVectors(bench.output() ? txCount : 1, 0, pubKeys, secKeys, sigs, msgHashes, invalid);
130130

131131
// Benchmark.
132-
bench.minEpochIterations(epoch_iters).run([&] {
132+
bench.minEpochIterations(bench.output() ? epoch_iters : 1).run([&] {
133133
for (size_t i = 0; i < pubKeys.size(); i++) {
134134
bool ok = sigs[i].VerifyInsecure(pubKeys[i], msgHashes[i]);
135135
assert(ok);
@@ -154,10 +154,10 @@ static void BLS_Verify_LargeBlockSelfAggregated(size_t txCount, benchmark::Bench
154154
std::vector<CBLSSignature> sigs;
155155
std::vector<uint256> msgHashes;
156156
std::vector<bool> invalid;
157-
BuildTestVectors(txCount, 0, pubKeys, secKeys, sigs, msgHashes, invalid);
157+
BuildTestVectors(bench.output() ? txCount : 1, 0, pubKeys, secKeys, sigs, msgHashes, invalid);
158158

159159
// Benchmark.
160-
bench.minEpochIterations(epoch_iters).run([&] {
160+
bench.minEpochIterations(bench.output() ? epoch_iters : 1).run([&] {
161161
CBLSSignature aggSig = CBLSSignature::AggregateInsecure(sigs);
162162
bool ok = aggSig.VerifyInsecureAggregated(pubKeys, msgHashes);
163163
assert(ok);
@@ -181,12 +181,12 @@ static void BLS_Verify_LargeAggregatedBlock(size_t txCount, benchmark::Bench& be
181181
std::vector<CBLSSignature> sigs;
182182
std::vector<uint256> msgHashes;
183183
std::vector<bool> invalid;
184-
BuildTestVectors(txCount, 0, pubKeys, secKeys, sigs, msgHashes, invalid);
184+
BuildTestVectors(bench.output() ? txCount : 1, 0, pubKeys, secKeys, sigs, msgHashes, invalid);
185185

186186
CBLSSignature aggSig = CBLSSignature::AggregateInsecure(sigs);
187187

188188
// Benchmark.
189-
bench.minEpochIterations(epoch_iters).run([&] {
189+
bench.minEpochIterations(bench.output() ? epoch_iters : 1).run([&] {
190190
bool ok = aggSig.VerifyInsecureAggregated(pubKeys, msgHashes);
191191
assert(ok);
192192
});
@@ -224,7 +224,7 @@ static void BLS_Verify_LargeAggregatedBlock1000PreVerified(benchmark::Bench& ben
224224
}
225225

226226
// Benchmark.
227-
bench.minEpochIterations(10).run([&] {
227+
bench.minEpochIterations(bench.output() ? 10 : 1).run([&] {
228228
std::vector<CBLSPublicKey> nonvalidatedPubKeys;
229229
std::vector<uint256> nonvalidatedHashes;
230230
nonvalidatedPubKeys.reserve(pubKeys.size());
@@ -255,13 +255,13 @@ static void BLS_Verify_Batched(benchmark::Bench& bench)
255255
std::vector<CBLSSignature> sigs;
256256
std::vector<uint256> msgHashes;
257257
std::vector<bool> invalid;
258-
BuildTestVectors(1000, 10, pubKeys, secKeys, sigs, msgHashes, invalid);
258+
BuildTestVectors(bench.output() ? 1000 : 1, 10, pubKeys, secKeys, sigs, msgHashes, invalid);
259259

260260
// Benchmark.
261261
size_t i = 0;
262262
size_t j = 0;
263263
size_t batchSize = 16;
264-
bench.minEpochIterations(1000).run([&] {
264+
bench.minEpochIterations(bench.output() ? 1000 : 1).run([&] {
265265
j++;
266266
if ((j % batchSize) != 0) {
267267
return;
@@ -311,7 +311,7 @@ static void BLS_Verify_BatchedParallel(benchmark::Bench& bench)
311311
std::vector<CBLSSignature> sigs;
312312
std::vector<uint256> msgHashes;
313313
std::vector<bool> invalid;
314-
BuildTestVectors(1000, 10, pubKeys, secKeys, sigs, msgHashes, invalid);
314+
BuildTestVectors(bench.output() ? 1000 : 1, 10, pubKeys, secKeys, sigs, msgHashes, invalid);
315315

316316
std::list<std::pair<size_t, std::future<bool>>> futures;
317317

@@ -324,7 +324,7 @@ static void BLS_Verify_BatchedParallel(benchmark::Bench& bench)
324324
blsWorker.Start();
325325

326326
// Benchmark.
327-
bench.minEpochIterations(1000).run([&] {
327+
bench.minEpochIterations(bench.output() ? 1000 : 1).run([&] {
328328
if (futures.size() < 100) {
329329
while (futures.size() < 10000) {
330330
size_t i = 0;

src/bench/bls_dkg.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ static void BLSDKG_GenerateContributions(benchmark::Bench& bench, uint32_t epoch
113113
blsWorker.Start();
114114
std::vector<CBLSId> ids;
115115
std::vector<Member> members;
116+
if (!bench.output()) {
117+
epoch_iters = 1;
118+
quorumSize = 1;
119+
}
116120
for (const int i : irange::range(quorumSize)) {
117121
uint256 id;
118122
WriteLE64(id.begin(), i + 1);
@@ -136,6 +140,10 @@ static void BLSDKG_GenerateContributions(benchmark::Bench& bench, uint32_t epoch
136140

137141
static void BLSDKG_InitDKG(benchmark::Bench& bench, uint32_t epoch_iters, int quorumSize)
138142
{
143+
if (!bench.output()) {
144+
epoch_iters = 1;
145+
quorumSize = 1;
146+
}
139147
bench.minEpochIterations(epoch_iters).run([&] {
140148
DKG d(quorumSize);
141149
});
@@ -151,6 +159,12 @@ static void BLSDKG_InitDKG(benchmark::Bench& bench, uint32_t epoch_iters, int qu
151159
#define BENCH_BuildQuorumVerificationVectors(name, quorumSize, epoch_iters) \
152160
static void BLSDKG_BuildQuorumVerificationVectors_##name##_##quorumSize(benchmark::Bench& bench) \
153161
{ \
162+
if (!bench.output()) { \
163+
std::unique_ptr<DKG> ptr = std::make_unique<DKG>(1); \
164+
ptr->Bench_BuildQuorumVerificationVectors(bench, 1); \
165+
ptr.reset(); \
166+
return; \
167+
} \
154168
std::unique_ptr<DKG> ptr = std::make_unique<DKG>(quorumSize); \
155169
ptr->Bench_BuildQuorumVerificationVectors(bench, epoch_iters); \
156170
ptr.reset(); \
@@ -160,9 +174,15 @@ static void BLSDKG_InitDKG(benchmark::Bench& bench, uint32_t epoch_iters, int qu
160174
#define BENCH_VerifyContributionShares(name, quorumSize, invalidCount, aggregated, epoch_iters) \
161175
static void BLSDKG_VerifyContributionShares_##name##_##quorumSize(benchmark::Bench& bench) \
162176
{ \
163-
std::unique_ptr<DKG> ptr = std::make_unique<DKG>(quorumSize); \
164-
ptr->Bench_VerifyContributionShares(bench, invalidCount, aggregated, epoch_iters); \
165-
ptr.reset(); \
177+
if (!bench.output()) { \
178+
std::unique_ptr<DKG> ptr = std::make_unique<DKG>(1); \
179+
ptr->Bench_VerifyContributionShares(bench, invalidCount, aggregated, 1); \
180+
ptr.reset(); \
181+
return; \
182+
} \
183+
std::unique_ptr<DKG> ptr = std::make_unique<DKG>(quorumSize); \
184+
ptr->Bench_VerifyContributionShares(bench, invalidCount, aggregated, epoch_iters); \
185+
ptr.reset(); \
166186
} \
167187
BENCHMARK(BLSDKG_VerifyContributionShares_##name##_##quorumSize)
168188

0 commit comments

Comments
 (0)