@@ -4,7 +4,7 @@ const crypto = require('crypto');
44const ArgumentParser = require ( 'argparse' ) . ArgumentParser ;
55//const itertools = require('@aureooms/js-itertools');
66const XorShift128Plus = require ( 'xorshift.js' ) . XorShift128Plus ;
7- const { ZZ } = require ( '..' ) ;
7+ const { ZZ , DEFAULT_DISPLAY_BASE , DEFAULT_REPRESENTATION_BASE } = require ( '..' ) ;
88const BN = require ( 'bn.js' ) ;
99
1010const parser = new ArgumentParser ( ) ;
@@ -20,29 +20,40 @@ console.log('operand size (bytes):', M);
2020console . log ( 'number of operations:' , N ) ;
2121console . 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+
2328const prng = new XorShift128Plus ( seed ) ;
2429const _x = prng . randomBytes ( M ) . toString ( 'hex' ) ;
25- console . log ( '_x:' , _x ) ;
30+ console . log ( '_x:' , _show ( _x ) ) ;
2631const _y = prng . randomBytes ( M ) . toString ( 'hex' ) ;
27- console . log ( '_y:' , _y ) ;
32+ console . log ( '_y:' , _show ( _y ) ) ;
2833
2934let x = ZZ . from ( _x , 16 ) ;
3035const 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
3647console . timeEnd ( 'prepare' ) ;
3748
3849console . time ( 'loop' ) ;
3950for ( 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}
4657console . 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