modular: Add comment. Add benchmark
This commit is contained in:
parent
53ff287bf7
commit
11f1626ecc
10
benchmark/modular.js
Normal file
10
benchmark/modular.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { run, mark } from 'micro-bmark';
|
||||||
|
import { secp256k1 } from '../secp256k1.js';
|
||||||
|
|
||||||
|
run(async () => {
|
||||||
|
console.log(`\x1b[36mmodular, secp256k1 field\x1b[0m`);
|
||||||
|
const { Fp } = secp256k1.CURVE;
|
||||||
|
await mark('invert a', 30000, () => Fp.inv(2n ** 232n - 5910n));
|
||||||
|
await mark('invert b', 30000, () => Fp.inv(2n ** 231n - 5910n));
|
||||||
|
await mark('sqrt', 15000, () => Fp.sqrt(2n ** 231n - 5910n));
|
||||||
|
});
|
@ -56,6 +56,7 @@ export function invert(number: bigint, modulo: bigint): bigint {
|
|||||||
throw new Error(`invert: expected positive integers, got n=${number} mod=${modulo}`);
|
throw new Error(`invert: expected positive integers, got n=${number} mod=${modulo}`);
|
||||||
}
|
}
|
||||||
// Eucledian GCD https://brilliant.org/wiki/extended-euclidean-algorithm/
|
// Eucledian GCD https://brilliant.org/wiki/extended-euclidean-algorithm/
|
||||||
|
// Fermat's little theorem "CT-like" version inv(n) = n^(m-2) mod m is 30x slower.
|
||||||
let a = mod(number, modulo);
|
let a = mod(number, modulo);
|
||||||
let b = modulo;
|
let b = modulo;
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
|
Loading…
Reference in New Issue
Block a user