Update benchmark API

This commit is contained in:
dapplion 2021-04-05 18:03:49 +02:00
parent ac9564d53a
commit 3bf2d48e2e
3 changed files with 13 additions and 17 deletions

View File

@ -86,29 +86,25 @@ import {aggCount, runs} from "./params";
// Verify multiple signatures // Verify multiple signatures
await runBenchmark<{pks: PublicKey[]; msgs: Uint8Array[]; sigs: Signature[]}, boolean>({ await runBenchmark({
id: `${implementation} verifyMultipleSignatures (${aggCount})`, id: `${implementation} verifyMultipleSignatures (${aggCount})`,
prepareTest: () => { prepareTest: () => {
const dataArr = range(aggCount).map(() => { const sets = range(aggCount).map(() => {
const sk = bls.SecretKey.fromKeygen(); const sk = bls.SecretKey.fromKeygen();
const pk = sk.toPublicKey(); const pk = sk.toPublicKey();
const msg = randomMessage(); const msg = randomMessage();
const sig = sk.sign(msg); const sig = sk.sign(msg);
return {pk, msg, sig}; return {publicKey: pk, message: msg, signature: sig};
}); });
const pks = dataArr.map((data) => data.pk);
const msgs = dataArr.map((data) => data.msg);
const sigs = dataArr.map((data) => data.sig);
return { return {
input: {pks, msgs, sigs}, input: sets,
resultCheck: (valid) => valid === true, resultCheck: (valid) => valid === true,
}; };
}, },
testRunner: ({pks, msgs, sigs}) => { testRunner: (sets) => {
return bls.Signature.verifyMultipleSignatures(pks, msgs, sigs); return bls.Signature.verifyMultipleSignatures(sets);
}, },
runs, runs,
}); });

View File

@ -12,7 +12,7 @@ import {range, randomMessage} from "../test/util";
const pk = sk.toPublicKey(); const pk = sk.toPublicKey();
const msg = randomMessage(); const msg = randomMessage();
const sig = sk.sign(msg); const sig = sk.sign(msg);
return {pk, msg, sig}; return {publicKey: pk, message: msg, signature: sig};
}); });
const startMulti = process.hrtime.bigint(); const startMulti = process.hrtime.bigint();
@ -21,8 +21,8 @@ import {range, randomMessage} from "../test/util";
const diffMulti = endMulti - startMulti; const diffMulti = endMulti - startMulti;
const startSingle = process.hrtime.bigint(); const startSingle = process.hrtime.bigint();
for (const {pk, msg, sig} of dataArr) { for (const {publicKey, message, signature} of dataArr) {
sig.verify(pk, msg); signature.verify(publicKey, message);
} }
const endSingle = process.hrtime.bigint(); const endSingle = process.hrtime.bigint();
const diffSingle = endSingle - startSingle; const diffSingle = endSingle - startSingle;

View File

@ -2,7 +2,7 @@
# yarn lockfile v1 # yarn lockfile v1
noble-bls12-381@^0.6.1: noble-bls12-381@^0.7.2:
version "0.6.1" version "0.7.2"
resolved "https://registry.yarnpkg.com/noble-bls12-381/-/noble-bls12-381-0.6.1.tgz#b44bb5443b4b5c409723f19a8288155f0b3ad126" resolved "https://registry.yarnpkg.com/noble-bls12-381/-/noble-bls12-381-0.7.2.tgz#9a9384891569ba32785d6e4ff8588b783487eae4"
integrity sha512-Dt0lq24ez75HqOqNIsxxbzfY7YOuwArtE3H6Clp1XbwnY4Ga1OjFbTaXq5aDBE3+ab1wLK11s0b3yR3+RiWWqw== integrity sha512-Z5isbU6opuWPL3dxsGqO5BdOE8WP1XUM7HFIn/xeE5pATTnml/PEIy4MFQQrktHiitkuJdsCDtzEOnS9eIpC3Q==