From 8ab0047d386ce9d9ee2bd2a7da5336857a351078 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 28 Feb 2021 00:15:49 +0300 Subject: [PATCH] bench: Tweak BLS benchmarks (#4012) * bench: Add a simple BLS signature aggregation benchmark * bench: Tweak `BLS_*KeyAggregate_Normal` benchmarks * bench: Adjust the expected number of iterations for `BLS_*KeyAggregate_Normal` benchmarks * bench: Add LargeBlock*100 benchmarks, drop LargeBlock*10000 ones These huge ones are kind of meaningless (results are ~10x slower than 1000) and it's a waste of time. Smaller ones should give an idea if there is a performance drop with the growth of the "block" size. --- src/bench/bls.cpp | 63 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/src/bench/bls.cpp b/src/bench/bls.cpp index d9e808fa27..0b7ea224b3 100644 --- a/src/bench/bls.cpp +++ b/src/bench/bls.cpp @@ -61,8 +61,7 @@ static void BLS_PubKeyAggregate_Normal(benchmark::State& state) // Benchmark. while (state.KeepRunning()) { - CBLSPublicKey k(pubKey1); - k.AggregateInsecure(pubKey2); + pubKey1.AggregateInsecure(pubKey2); } } @@ -71,13 +70,25 @@ static void BLS_SecKeyAggregate_Normal(benchmark::State& state) CBLSSecretKey secKey1, secKey2; secKey1.MakeNewKey(); secKey2.MakeNewKey(); - CBLSPublicKey pubKey1 = secKey1.GetPublicKey(); - CBLSPublicKey pubKey2 = secKey2.GetPublicKey(); // Benchmark. while (state.KeepRunning()) { - CBLSSecretKey k(secKey1); - k.AggregateInsecure(secKey2); + secKey1.AggregateInsecure(secKey2); + } +} + +static void BLS_SignatureAggregate_Normal(benchmark::State& state) +{ + uint256 hash = GetRandHash(); + CBLSSecretKey secKey1, secKey2; + secKey1.MakeNewKey(); + secKey2.MakeNewKey(); + CBLSSignature sig1 = secKey1.Sign(hash); + CBLSSignature sig2 = secKey2.Sign(hash); + + // Benchmark. + while (state.KeepRunning()) { + sig1.AggregateInsecure(sig2); } } @@ -136,16 +147,16 @@ static void BLS_Verify_LargeBlock(size_t txCount, benchmark::State& state) } } +static void BLS_Verify_LargeBlock100(benchmark::State& state) +{ + BLS_Verify_LargeBlock(100, state); +} + static void BLS_Verify_LargeBlock1000(benchmark::State& state) { BLS_Verify_LargeBlock(1000, state); } -static void BLS_Verify_LargeBlock10000(benchmark::State& state) -{ - BLS_Verify_LargeBlock(10000, state); -} - static void BLS_Verify_LargeBlockSelfAggregated(size_t txCount, benchmark::State& state) { BLSPublicKeyVector pubKeys; @@ -162,16 +173,16 @@ static void BLS_Verify_LargeBlockSelfAggregated(size_t txCount, benchmark::State } } +static void BLS_Verify_LargeBlockSelfAggregated100(benchmark::State& state) +{ + BLS_Verify_LargeBlockSelfAggregated(100, state); +} + static void BLS_Verify_LargeBlockSelfAggregated1000(benchmark::State& state) { BLS_Verify_LargeBlockSelfAggregated(1000, state); } -static void BLS_Verify_LargeBlockSelfAggregated10000(benchmark::State& state) -{ - BLS_Verify_LargeBlockSelfAggregated(10000, state); -} - static void BLS_Verify_LargeAggregatedBlock(size_t txCount, benchmark::State& state) { BLSPublicKeyVector pubKeys; @@ -189,16 +200,16 @@ static void BLS_Verify_LargeAggregatedBlock(size_t txCount, benchmark::State& st } } +static void BLS_Verify_LargeAggregatedBlock100(benchmark::State& state) +{ + BLS_Verify_LargeAggregatedBlock(100, state); +} + static void BLS_Verify_LargeAggregatedBlock1000(benchmark::State& state) { BLS_Verify_LargeAggregatedBlock(1000, state); } -static void BLS_Verify_LargeAggregatedBlock10000(benchmark::State& state) -{ - BLS_Verify_LargeAggregatedBlock(10000, state); -} - static void BLS_Verify_LargeAggregatedBlock1000PreVerified(benchmark::State& state) { BLSPublicKeyVector pubKeys; @@ -348,15 +359,17 @@ static void BLS_Verify_BatchedParallel(benchmark::State& state) } } -BENCHMARK(BLS_PubKeyAggregate_Normal, 300 * 1000) -BENCHMARK(BLS_SecKeyAggregate_Normal, 700 * 1000) +BENCHMARK(BLS_PubKeyAggregate_Normal, 140 * 1000) +BENCHMARK(BLS_SecKeyAggregate_Normal, 800 * 1000) +BENCHMARK(BLS_SignatureAggregate_Normal, 100 * 1000) BENCHMARK(BLS_Sign_Normal, 600) BENCHMARK(BLS_Verify_Normal, 350) +BENCHMARK(BLS_Verify_LargeBlock100, 3) BENCHMARK(BLS_Verify_LargeBlock1000, 1) +BENCHMARK(BLS_Verify_LargeBlockSelfAggregated100, 7) BENCHMARK(BLS_Verify_LargeBlockSelfAggregated1000, 1) -BENCHMARK(BLS_Verify_LargeBlockSelfAggregated10000, 1) +BENCHMARK(BLS_Verify_LargeAggregatedBlock100, 7) BENCHMARK(BLS_Verify_LargeAggregatedBlock1000, 1) -BENCHMARK(BLS_Verify_LargeAggregatedBlock10000, 1) BENCHMARK(BLS_Verify_LargeAggregatedBlock1000PreVerified, 5) BENCHMARK(BLS_Verify_Batched, 500) BENCHMARK(BLS_Verify_BatchedParallel, 1000)