Skip to content

Commit

Permalink
Update dev dependencies (indutny#220)
Browse files Browse the repository at this point in the history
* update .gitignore

* update .travis.yml config

* update dev dependencies

* adjust code for rules in new semistandard version

* standardx with tweaks instead semistandard

* style changes for latest standard

* move bignum in benchmark to optionalDependencies

* add lock file for benchmark
  • Loading branch information
fanatid authored Aug 9, 2019
1 parent f953de2 commit cdee8c9
Show file tree
Hide file tree
Showing 16 changed files with 2,544 additions and 146 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
coverage/
node_modules/

npm-debug.log
1.js
package-lock.json
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
sudo: false
language: node_js
cache:
yarn: true
directories:
- node_modules
node_js:
- "lts/*"
- "8"
- "10"
- "node"
- "12"
env:
matrix:
- TEST_SUITE=unit
Expand Down
128 changes: 72 additions & 56 deletions benchmarks/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/* eslint-disable new-cap, no-new */
/* eslint-disable new-cap, no-new */

var benchmark = require('benchmark');
var crypto = require('crypto');
var bn = require('../');
var bignum = require('bignum');
var bignum;
try {
bignum = require('bignum');
} catch (err) {
console.log('Load bignum error: ' + err.message.split('\n')[0]);
}
var sjcl = require('eccjs').sjcl.bn;
var bigi = require('bigi');
var BigInteger = require('js-big-integer').BigInteger;
Expand Down Expand Up @@ -31,6 +36,10 @@ function add (op, obj) {
console.log('Benchmarking: ' + op);

Object.keys(obj).forEach(function (name) {
if (name === 'bignum' && bignum === undefined) {
return;
}

if (!selfOnly || name === 'bn.js') {
var testFn = obj[name];
suite.add(name + '#' + op, function () {
Expand Down Expand Up @@ -99,10 +108,12 @@ while (fixtures.length < 25) {
fixture.b1j = new bn(bj, 16);

// bignum
fixture.a2 = new bignum(a, 16);
fixture.b2 = new bignum(b, 16);
fixture.a2j = new bignum(aj, 16);
fixture.b2j = new bignum(bj, 16);
if (bignum) {
fixture.a2 = new bignum(a, 16);
fixture.b2 = new bignum(b, 16);
fixture.a2j = new bignum(aj, 16);
fixture.b2j = new bignum(bj, 16);
}

// bigi
fixture.a4 = new bigi(a, 16);
Expand Down Expand Up @@ -131,13 +142,15 @@ while (fixtures.length < 25) {

//
fixture.as1 = fixture.a1.mul(fixture.a1).iaddn(0x2adbeef);
fixture.as2 = fixture.a2.mul(fixture.a2).add(0x2adbeef);
if (bignum) {
fixture.as2 = fixture.a2.mul(fixture.a2).add(0x2adbeef);
}
fixture.as4 = fixture.a4.multiply(fixture.a4).add(bigi.valueOf(0x2adbeef));
// fixture.as5 = fixture.a5.mul(fixture.a5).add(0x2adbeef);
fixture.as6 = fixture.a6.multiply(fixture.a6).add(
new BigInteger('2adbeef', 16));
new BigInteger('2adbeef', 16));
fixture.as8 = fixture.a8.multiply(fixture.a8).add(
SilentMattBigInteger.parse('2adbeef', 16));
SilentMattBigInteger.parse('2adbeef', 16));

fixture.am1 = fixture.a1.toRed(bn.red('k256'));
fixture.am5 = new sjcl.prime.p256k(fixture.a5);
Expand All @@ -152,13 +165,13 @@ add('create-10', {
'bn.js': function (fixture) {
new bn(fixture.a10base, 10);
},
'bignum': function (fixture) {
bignum: function (fixture) {
new bignum(fixture.a10base, 10);
},
'bigi': function (fixture) {
bigi: function (fixture) {
new bigi(fixture.a10base, 10);
},
'yaffle': function (fixture) {
yaffle: function (fixture) {
new BigInteger(fixture.a10base, 10);
},
'silentmatt-biginteger': function (fixture) {
Expand All @@ -170,16 +183,16 @@ add('create-hex', {
'bn.js': function (fixture) {
new bn(fixture.a16base, 16);
},
'bignum': function (fixture) {
bignum: function (fixture) {
new bignum(fixture.a16base, 16);
},
'bigi': function (fixture) {
bigi: function (fixture) {
new bigi(fixture.a16base, 16);
},
'sjcl': function (fixture) {
sjcl: function (fixture) {
new sjcl(fixture.a16base);
},
'yaffle': function (fixture) {
yaffle: function (fixture) {
new BigInteger(fixture.a16base, 16);
},
'silentmatt-biginteger': function (fixture) {
Expand All @@ -191,13 +204,13 @@ add('toString-10', {
'bn.js': function (fixture) {
fixture.a1.toString(10);
},
'bignum': function (fixture) {
bignum: function (fixture) {
fixture.a2.toString(10);
},
'bigi': function (fixture) {
bigi: function (fixture) {
fixture.a4.toString(10);
},
'yaffle': function (fixture) {
yaffle: function (fixture) {
fixture.a6.toString(10);
},
'silentmatt-biginteger': function (fixture) {
Expand All @@ -209,16 +222,16 @@ add('toString-hex', {
'bn.js': function (fixture) {
fixture.a1.toString(16);
},
'bignum': function (fixture) {
bignum: function (fixture) {
fixture.a2.toString(16);
},
'bigi': function (fixture) {
bigi: function (fixture) {
fixture.a4.toString(16);
},
'sjcl': function (fixture) {
sjcl: function (fixture) {
fixture.a5.toString(16);
},
'yaffle': function (fixture) {
yaffle: function (fixture) {
fixture.a6.toString(16);
},
'silentmatt-biginteger': function (fixture) {
Expand All @@ -230,16 +243,16 @@ add('add', {
'bn.js': function (fixture) {
fixture.a1.add(fixture.b1);
},
'bignum': function (fixture) {
bignum: function (fixture) {
fixture.a2.add(fixture.b2);
},
'bigi': function (fixture) {
bigi: function (fixture) {
fixture.a4.add(fixture.b4);
},
'sjcl': function (fixture) {
sjcl: function (fixture) {
fixture.a5.add(fixture.b5);
},
'yaffle': function (fixture) {
yaffle: function (fixture) {
fixture.a6.add(fixture.b6);
},
'silentmatt-biginteger': function (fixture) {
Expand All @@ -251,16 +264,16 @@ add('sub', {
'bn.js': function (fixture) {
fixture.b1.sub(fixture.a1);
},
'bignum': function (fixture) {
bignum: function (fixture) {
fixture.b2.sub(fixture.a2);
},
'bigi': function (fixture) {
bigi: function (fixture) {
fixture.b4.subtract(fixture.a4);
},
'sjcl': function (fixture) {
sjcl: function (fixture) {
fixture.b5.sub(fixture.a5);
},
'yaffle': function (fixture) {
yaffle: function (fixture) {
fixture.b6.subtract(fixture.a6);
},
'silentmatt-biginteger': function (fixture) {
Expand All @@ -275,16 +288,16 @@ add('mul', {
'bn.js[FFT]': function (fixture) {
fixture.a1.mulf(fixture.b1);
},
'bignum': function (fixture) {
bignum: function (fixture) {
fixture.a2.mul(fixture.b2);
},
'bigi': function (fixture) {
bigi: function (fixture) {
fixture.a4.multiply(fixture.b4);
},
'sjcl': function (fixture) {
sjcl: function (fixture) {
fixture.a5.mul(fixture.b5);
},
'yaffle': function (fixture) {
yaffle: function (fixture) {
fixture.a6.multiply(fixture.b6);
},
'silentmatt-biginteger': function (fixture) {
Expand All @@ -299,16 +312,16 @@ add('mul-jumbo', {
'bn.js[FFT]': function (fixture) {
fixture.a1j.mulf(fixture.b1j);
},
'bignum': function (fixture) {
bignum: function (fixture) {
fixture.a2j.mul(fixture.b2j);
},
'bigi': function (fixture) {
bigi: function (fixture) {
fixture.a4j.multiply(fixture.b4j);
},
'sjcl': function (fixture) {
sjcl: function (fixture) {
fixture.a5j.mul(fixture.b5j);
},
'yaffle': function (fixture) {
yaffle: function (fixture) {
fixture.a6j.multiply(fixture.b6j);
},
'silentmatt-biginteger': function (fixture) {
Expand All @@ -320,16 +333,16 @@ add('sqr', {
'bn.js': function (fixture) {
fixture.a1.mul(fixture.a1);
},
'bignum': function (fixture) {
bignum: function (fixture) {
fixture.a2.mul(fixture.a2);
},
'bigi': function (fixture) {
bigi: function (fixture) {
fixture.a4.square();
},
'sjcl': function (fixture) {
sjcl: function (fixture) {
fixture.a5.mul(fixture.a5);
},
'yaffle': function (fixture) {
yaffle: function (fixture) {
fixture.a6.multiply(fixture.a6);
},
'silentmatt-biginteger': function (fixture) {
Expand All @@ -341,13 +354,13 @@ add('div', {
'bn.js': function (fixture) {
fixture.as1.div(fixture.a1);
},
'bignum': function (fixture) {
bignum: function (fixture) {
fixture.as2.div(fixture.a2);
},
'bigi': function (fixture) {
bigi: function (fixture) {
fixture.as4.divide(fixture.a4);
},
'yaffle': function (fixture) {
yaffle: function (fixture) {
fixture.as6.divide(fixture.a6);
},
'silentmatt-biginteger': function (fixture) {
Expand All @@ -359,13 +372,13 @@ add('mod', {
'bn.js': function (fixture) {
fixture.as1.mod(fixture.a1);
},
'bignum': function (fixture) {
bignum: function (fixture) {
fixture.as2.mod(fixture.a2);
},
'bigi': function (fixture) {
bigi: function (fixture) {
fixture.as4.mod(fixture.a4);
},
'yaffle': function (fixture) {
yaffle: function (fixture) {
var remainder = fixture.as6.remainder(fixture.a6);
return remainder.compareTo(BigInteger.ZERO) < 0
? remainder.add(fixture.a6)
Expand All @@ -383,14 +396,17 @@ add('mul-mod k256', {
'bn.js': function (fixture) {
fixture.am1.redSqr();
},
'sjcl': function (fixture) {
sjcl: function (fixture) {
fixture.am5.square().fullReduce();
}
});

var prime1 = new bignum(
'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f',
16);
var prime1;
if (bignum) {
prime1 = new bignum(
'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f',
16);
}
// var prime4 = new bigi(
// 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f',
// 16);
Expand All @@ -401,7 +417,7 @@ add('pow k256', {
'bn.js': function (fixture) {
fixture.am1.redPow(fixture.pow1);
},
'bignum': function (fixture) {
bignum: function (fixture) {
fixture.a2.powm(fixture.a2, prime1);
}
});
Expand All @@ -410,7 +426,7 @@ add('invm k256', {
'bn.js': function (fixture) {
fixture.am1.redInvm();
},
'sjcl': function (fixture) {
sjcl: function (fixture) {
fixture.am5.inverseMod(prime5);
}
});
Expand All @@ -419,7 +435,7 @@ add('gcd', {
'bn.js': function (fixture) {
fixture.a1.gcd(fixture.b1);
},
'bigi': function (fixture) {
bigi: function (fixture) {
fixture.a4.gcd(fixture.b4);
}
});
Expand Down
6 changes: 4 additions & 2 deletions benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
"benchmark": "^1.0.0",
"bigi": "*",
"biginteger": "*",
"bignum": "^0.11.0",
"eccjs": "^0.3.1",
"js-big-integer": "*",
"js-big-integer": "1.0.2",
"xorshift.js": "^1.0.0"
},
"optionalDependencies": {
"bignum": "^0.13.0"
}
}
Loading

0 comments on commit cdee8c9

Please sign in to comment.