benchmark: add tonneli-shanks sqrt

This commit is contained in:
Paul Miller 2023-02-27 22:59:27 +00:00
parent fa5105aef2
commit 0e0d0f530d
No known key found for this signature in database
GPG Key ID: 697079DA6878B89B

@ -1,10 +1,13 @@
import { run, mark } from 'micro-bmark'; import { run, mark } from 'micro-bmark';
import { secp256k1 } from '../secp256k1.js'; import { secp256k1 } from '../secp256k1.js';
import { Fp } from '../abstract/modular.js';
run(async () => { run(async () => {
console.log(`\x1b[36mmodular, secp256k1 field\x1b[0m`); console.log(`\x1b[36mmodular, secp256k1 field\x1b[0m`);
const { Fp } = secp256k1.CURVE; const { Fp: secpFp } = secp256k1.CURVE;
await mark('invert a', 30000, () => Fp.inv(2n ** 232n - 5910n)); await mark('invert a', 300000, () => secpFp.inv(2n ** 232n - 5910n));
await mark('invert b', 30000, () => Fp.inv(2n ** 231n - 5910n)); await mark('invert b', 300000, () => secpFp.inv(2n ** 231n - 5910n));
await mark('sqrt', 15000, () => Fp.sqrt(2n ** 231n - 5910n)); await mark('sqrt p = 3 mod 4', 15000, () => secpFp.sqrt(2n ** 231n - 5910n));
const FpStark = Fp(BigInt('0x800000000000011000000000000000000000000000000000000000000000001'));
await mark('sqrt tonneli-shanks', 500, () => FpStark.sqrt(2n ** 231n - 5909n))
}); });