From fa8a89c4852b23673b927df32ee23fc0cbdc780f Mon Sep 17 00:00:00 2001 From: dapplion Date: Fri, 4 Dec 2020 21:05:48 +0000 Subject: [PATCH] Benchmark verifyMultipleSignatures savings --- benchmark/package.json | 2 +- benchmark/verifyMultipleSignaturesSavings.ts | 38 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 benchmark/verifyMultipleSignaturesSavings.ts diff --git a/benchmark/package.json b/benchmark/package.json index 4b404a9..1824cf6 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -5,7 +5,7 @@ "license": "MIT", "scripts": { "benchmark": "ts-node index", - "benchmark:all": "ts-node index && ts-node noble" + "benchmark:all": "ts-node index && ts-node noble && ts-node verifyMultipleSignaturesSavings" }, "dependencies": { "noble-bls12-381": "^0.6.1" diff --git a/benchmark/verifyMultipleSignaturesSavings.ts b/benchmark/verifyMultipleSignaturesSavings.ts new file mode 100644 index 0000000..31b5245 --- /dev/null +++ b/benchmark/verifyMultipleSignaturesSavings.ts @@ -0,0 +1,38 @@ +import {runForAllImplementations} from "../test/switch"; +import {range, randomMessage} from "../test/util"; + +(async function () { + console.log("verifyMultipleSignatures savings"); + console.log(["Impl", "# sigs", "ratio multi/single"].join("\t")); + + await runForAllImplementations(async (bls, implementation) => { + for (const aggCount of [2, 5, 10, 20, 50, 100]) { + const dataArr = range(aggCount).map(() => { + const sk = bls.SecretKey.fromKeygen(); + const pk = sk.toPublicKey(); + const msg = randomMessage(); + const sig = sk.sign(msg); + return {pk, msg, sig}; + }); + + const pks = dataArr.map((data) => data.pk); + const msgs = dataArr.map((data) => data.msg); + const sigs = dataArr.map((data) => data.sig); + + const startMulti = process.hrtime.bigint(); + bls.Signature.verifyMultipleSignatures(pks, msgs, sigs); + const endMulti = process.hrtime.bigint(); + const diffMulti = endMulti - startMulti; + + const startSingle = process.hrtime.bigint(); + for (const {pk, msg, sig} of dataArr) { + sig.verify(pk, msg); + } + const endSingle = process.hrtime.bigint(); + const diffSingle = endSingle - startSingle; + + const ratio = Number(diffMulti) / Number(diffSingle); + console.log([implementation, aggCount, ratio.toPrecision(2)].join("\t")); + } + }); +})();