Skip to content

Commit b11e0af

Browse files
🚀 perf(profile): Improve UX for add.
1 parent 50e9ac0 commit b11e0af

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

_profile/add.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +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 { ZZ } = require('..');
7+
const { ZZ , DEFAULT_DISPLAY_BASE , DEFAULT_REPRESENTATION_BASE } = require('..');
88
const BN = require('bn.js');
99

1010
const parser = new ArgumentParser();
@@ -20,29 +20,40 @@ console.log('operand size (bytes):', M);
2020
console.log('number of operations:', N);
2121
console.log('seed:', seed);
2222

23+
const MAX_PRINT_DIGITS = 79;
24+
const _show = _x => _x.length <= MAX_PRINT_DIGITS ?
25+
_x :
26+
_x.slice(0,(MAX_PRINT_DIGITS-3)/2) + '...' + _x.slice(_x.length-(MAX_PRINT_DIGITS-3)/2) ;
27+
2328
const prng = new XorShift128Plus(seed);
2429
const _x = prng.randomBytes(M).toString('hex');
25-
console.log('_x:', _x);
30+
console.log('_x:', _show(_x));
2631
const _y = prng.randomBytes(M).toString('hex');
27-
console.log('_y:', _y);
32+
console.log('_y:', _show(_y));
2833

2934
let x = ZZ.from(_x, 16);
3035
const y = ZZ.from(_y, 16);
3136
//let x = BigInt('0x'+_x) ;
3237
//const y = BigInt('0x'+_y) ;
3338
//let x = new BN(_x,16) ;
3439
//const y = new BN(_y,16) ;
40+
let z = x;
41+
42+
console.log('limbs x:', x.limbs.length);
43+
console.log('limbs y:', y.limbs.length);
44+
console.log('DEFAULT_DISPLAY_BASE:', DEFAULT_DISPLAY_BASE);
45+
console.log('DEFAULT_REPRESENTATION_BASE:', DEFAULT_REPRESENTATION_BASE);
3546

3647
console.timeEnd('prepare');
3748

3849
console.time('loop');
3950
for (let k = 0; k < N; ++k) {
4051
//x *= y;
41-
x = x.add(y);
42-
x = x.sub(y);
52+
z = z.add(y);
53+
z = z.sub(y);
4354
//x = x + y;
4455
//x = x - y;
4556
}
4657
console.timeEnd('loop');
4758

48-
if (Math.random() < 0.0001) console.log(x);
59+
console.log(z.toString(16) === z.toString(16) ? 'OK' : 'ERROR: NOT OK');

0 commit comments

Comments
 (0)