Skip to content

Commit d3e36fb

Browse files
🚀 perf: Progress on profiling and benchmarking.
1 parent d3c484c commit d3e36fb

File tree

3 files changed

+74
-21
lines changed

3 files changed

+74
-21
lines changed

_benchmark/index.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,16 +371,21 @@ add('add', 'a768', 'b768');
371371
add('sub', 'a32', 'b32');
372372
add('sub', 'a768', 'b768');
373373

374-
add('mul', 'a32', 'b32');
375-
add('mul', 'a64', 'b64');
376-
add('mul', 'a128', 'b128');
377-
add('mul', 'a256', 'b256');
378-
add('mul', 'a512', 'b512');
379-
add('mul', 'a768', 'b768');
380-
add('mul', 'a1024', 'b1024');
381-
add('mul', 'a2048', 'b2048');
382-
add('mul', 'a4096', 'b4096');
383-
add('mul', 'a8192', 'b8192');
374+
const ALL_OPS = [
375+
[ 'a32', 'b32' ] ,
376+
[ 'a64', 'b64' ] ,
377+
[ 'a128', 'b128' ] ,
378+
[ 'a256', 'b256' ] ,
379+
[ 'a512', 'b512' ] ,
380+
[ 'a768', 'b768' ] ,
381+
[ 'a1024', 'b1024' ] ,
382+
[ 'a2048', 'b2048' ] ,
383+
[ 'a4096', 'b4096' ] ,
384+
[ 'a8192', 'b8192' ] ,
385+
] ;
386+
387+
for ( const [ a , b ] of ALL_OPS ) add('mul', a, b) ;
388+
for ( const [ a , b ] of ALL_OPS ) add('div', a, b) ;
384389

385390
add('sqr', 'a32');
386391
add('div', 'as1', 'a32');
@@ -418,6 +423,7 @@ for ( let i = 0; i < NFIXTURES; ++i ) {
418423
console.error('DIFFERENT OUTPUTS for', i, key) ;
419424
console.error(distinctResults) ;
420425
console.error(i, key, theseResults) ;
426+
console.error(fixtures[i]) ;
421427
}
422428
else {
423429
console.error(i, key, JSON.stringify(Object.keys(theseResults)), 'OK') ;

_profile/mod.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
console.time('prepare');
2+
require('@babel/polyfill');
3+
const crypto = require('crypto');
4+
const ArgumentParser = require('argparse').ArgumentParser;
5+
//const itertools = require('@aureooms/js-itertools');
6+
const XorShift128Plus = require('xorshift.js').XorShift128Plus;
7+
const { THRESHOLD_MUL_TOOM22 , THRESHOLD_DIV_DC } = require('@aureooms/js-integer-big-endian');
8+
const { ZZ , DEFAULT_DISPLAY_BASE , DEFAULT_REPRESENTATION_BASE } = require('..');
9+
const BN = require('bn.js');
10+
11+
const parser = new ArgumentParser();
12+
parser.addArgument(['M'], {defaultValue: 1000, nargs: '?'});
13+
parser.addArgument(['-N'], {defaultValue: 1000});
14+
parser.addArgument(['-s'], {defaultValue: process.env.SEED || crypto.randomBytes(16).toString('hex')});
15+
const args = parser.parseArgs();
16+
const M = args.M;
17+
const N = args.N;
18+
const seed = args.s;
19+
20+
console.log('operand size (bytes):', M);
21+
console.log('number of operations:', N);
22+
console.log('seed:', seed);
23+
24+
const prng = new XorShift128Plus(seed);
25+
const _x = prng.randomBytes(M).toString('hex');
26+
console.log('_x:', _x);
27+
const _y = prng.randomBytes(M).toString('hex');
28+
console.log('_y:', _y);
29+
30+
let x = ZZ.from(_x, 16);
31+
const y = ZZ.from(_y, 16);
32+
x.iadd(y.square());
33+
34+
console.log('limbs x:', x.limbs.length);
35+
console.log('limbs y:', y.limbs.length);
36+
console.log('DEFAULT_DISPLAY_BASE:', DEFAULT_DISPLAY_BASE);
37+
console.log('DEFAULT_REPRESENTATION_BASE:', DEFAULT_REPRESENTATION_BASE);
38+
console.log('THRESHOLD_MUL_TOOM22:', THRESHOLD_MUL_TOOM22);
39+
console.log('THRESHOLD_DIV_DC:', THRESHOLD_DIV_DC);
40+
41+
console.timeEnd('prepare');
42+
43+
console.time('loop');
44+
let z;
45+
for (let k = 0; k < N; ++k) {
46+
z = x.mod(y);
47+
}
48+
console.timeEnd('loop');
49+
50+
console.log(z.toString(16) === z.toString(16) ? 'OK' : 'ERROR: NOT OK');

_profile/mul.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const crypto = require('crypto');
44
const ArgumentParser = require('argparse').ArgumentParser;
55
//const itertools = require('@aureooms/js-itertools');
66
const XorShift128Plus = require('xorshift.js').XorShift128Plus;
7+
const { THRESHOLD_MUL_TOOM22 } = require('@aureooms/js-integer-big-endian');
78
const { ZZ } = require('..');
89
const BN = require('bn.js');
910

@@ -28,22 +29,18 @@ console.log('_y:', _y);
2829

2930
let x = ZZ.from(_x, 16);
3031
const y = ZZ.from(_y, 16);
31-
//let x = BigInt('0x'+_x) ;
32-
//const y = BigInt('0x'+_y) ;
33-
//let x = new BN(_x,16) ;
34-
//const y = new BN(_y,16) ;
32+
33+
console.log('limbs x:', x.limbs.length);
34+
console.log('limbs y:', y.limbs.length);
35+
console.log('THRESHOLD_MUL_TOOM22:', THRESHOLD_MUL_TOOM22);
3536

3637
console.timeEnd('prepare');
3738

3839
console.time('loop');
40+
let z;
3941
for (let k = 0; k < N; ++k) {
40-
x = x.mul(y);
41-
//x *= y;
42-
//x = x.add(y);
43-
//x = x.sub(y);
44-
//x = x + y;
45-
//x = x - y;
42+
z = x.mul(y);
4643
}
4744
console.timeEnd('loop');
4845

49-
if (Math.random() < 0.0001) console.log(x);
46+
if (Math.random() < 0.0001) console.log(z);

0 commit comments

Comments
 (0)