@@ -4,7 +4,7 @@ const crypto = require('crypto');
4
4
const ArgumentParser = require ( 'argparse' ) . ArgumentParser ;
5
5
//const itertools = require('@aureooms/js-itertools');
6
6
const XorShift128Plus = require ( 'xorshift.js' ) . XorShift128Plus ;
7
- const { ZZ } = require ( '..' ) ;
7
+ const { ZZ , DEFAULT_DISPLAY_BASE , DEFAULT_REPRESENTATION_BASE } = require ( '..' ) ;
8
8
const BN = require ( 'bn.js' ) ;
9
9
10
10
const parser = new ArgumentParser ( ) ;
@@ -20,29 +20,40 @@ console.log('operand size (bytes):', M);
20
20
console . log ( 'number of operations:' , N ) ;
21
21
console . log ( 'seed:' , seed ) ;
22
22
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
+
23
28
const prng = new XorShift128Plus ( seed ) ;
24
29
const _x = prng . randomBytes ( M ) . toString ( 'hex' ) ;
25
- console . log ( '_x:' , _x ) ;
30
+ console . log ( '_x:' , _show ( _x ) ) ;
26
31
const _y = prng . randomBytes ( M ) . toString ( 'hex' ) ;
27
- console . log ( '_y:' , _y ) ;
32
+ console . log ( '_y:' , _show ( _y ) ) ;
28
33
29
34
let x = ZZ . from ( _x , 16 ) ;
30
35
const y = ZZ . from ( _y , 16 ) ;
31
36
//let x = BigInt('0x'+_x) ;
32
37
//const y = BigInt('0x'+_y) ;
33
38
//let x = new BN(_x,16) ;
34
39
//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 ) ;
35
46
36
47
console . timeEnd ( 'prepare' ) ;
37
48
38
49
console . time ( 'loop' ) ;
39
50
for ( let k = 0 ; k < N ; ++ k ) {
40
51
//x *= y;
41
- x = x . add ( y ) ;
42
- x = x . sub ( y ) ;
52
+ z = z . add ( y ) ;
53
+ z = z . sub ( y ) ;
43
54
//x = x + y;
44
55
//x = x - y;
45
56
}
46
57
console . timeEnd ( 'loop' ) ;
47
58
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