Skip to content

Commit 79d2e35

Browse files
🚀 perf: More profiling code.
1 parent bea40e4 commit 79d2e35

File tree

3 files changed

+99
-3
lines changed

3 files changed

+99
-3
lines changed

_profile/add.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ console.timeEnd('prepare');
3737

3838
console.time('loop');
3939
for (let k = 0; k < N; ++k) {
40-
x = x.mul(y);
4140
//x *= y;
42-
//x = x.add(y);
43-
//x = x.sub(y);
41+
x = x.add(y);
42+
x = x.sub(y);
4443
//x = x + y;
4544
//x = x - y;
4645
}

_profile/iadd.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 *= y;
41+
x.iadd(y);
42+
x.isub(y);
43+
//x = x + y;
44+
//x = x - y;
45+
}
46+
console.timeEnd('loop');
47+
48+
if (Math.random() < 0.0001) console.log(x);

_profile/mul.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)