|
| 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 { ZZ } = require('..'); |
| 8 | +const BN = require('bn.js'); |
| 9 | + |
| 10 | +const parser = new ArgumentParser(); |
| 11 | +parser.addArgument(['M'], {defaultValue: 1000, nargs: '?'}); |
| 12 | +parser.addArgument(['-N'], {defaultValue: 1000}); |
| 13 | +parser.addArgument(['-s'], {defaultValue: process.env.SEED || crypto.randomBytes(16).toString('hex')}); |
| 14 | +const args = parser.parseArgs(); |
| 15 | +const M = args.M; |
| 16 | +const N = args.N; |
| 17 | +const seed = args.s; |
| 18 | + |
| 19 | +console.log('operand size (bytes):', M); |
| 20 | +console.log('number of operations:', N); |
| 21 | +console.log('seed:', seed); |
| 22 | + |
| 23 | +const prng = new XorShift128Plus(seed); |
| 24 | +const _x = prng.randomBytes(M).toString('hex'); |
| 25 | +console.log('_x:', _x); |
| 26 | +const _y = prng.randomBytes(M).toString('hex'); |
| 27 | +console.log('_y:', _y); |
| 28 | + |
| 29 | +let x = ZZ.from(_x, 16); |
| 30 | +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) ; |
| 35 | + |
| 36 | +console.timeEnd('prepare'); |
| 37 | + |
| 38 | +console.time('loop'); |
| 39 | +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; |
| 46 | +} |
| 47 | +console.timeEnd('loop'); |
| 48 | + |
| 49 | +if (Math.random() < 0.0001) console.log(x); |
0 commit comments