Skip to content

Commit 0d21b56

Browse files
committed
add BigInt to bench
1 parent 4b67505 commit 0d21b56

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

benchmarks/index.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* eslint-disable new-cap, no-new */
1+
/* global BigInt */
2+
/* eslint-disable new-cap, no-new, no-unused-expressions */
23

34
var benchmark = require('benchmark');
45
var crypto = require('crypto');
@@ -36,6 +37,10 @@ function add (op, obj) {
3637
console.log('Benchmarking: ' + op);
3738

3839
Object.keys(obj).forEach(function (name) {
40+
if (name === 'BigInt' && typeof BigInt === 'undefined') {
41+
return;
42+
}
43+
3944
if (name === 'bignum' && bignum === undefined) {
4045
return;
4146
}
@@ -113,6 +118,13 @@ while (fixtures.length < 25) {
113118
fixture.am1 = fixture.a1.toRed(bn.red('k256'));
114119
fixture.pow1 = fixture.am1.fromRed();
115120

121+
// BigInt
122+
fixture.a2 = BigInt(fixture.a1.toString(10));
123+
fixture.b2 = BigInt(fixture.b1.toString(10));
124+
fixture.a2j = BigInt(fixture.a1j.toString(10));
125+
fixture.b2j = BigInt(fixture.b1j.toString(10));
126+
fixture.as2 = fixture.a2 * fixture.a2 + 0x2adbeefn;
127+
116128
// bignum
117129
if (bignum) {
118130
fixture.a3 = new bignum(a, 16);
@@ -158,6 +170,9 @@ add('create-10', {
158170
'bn.js': function (fixture) {
159171
new bn(fixture.a10base, 10);
160172
},
173+
BigInt: function (fixture) {
174+
BigInt(fixture.a10base);
175+
},
161176
bignum: function (fixture) {
162177
new bignum(fixture.a10base, 10);
163178
},
@@ -197,6 +212,9 @@ add('toString-10', {
197212
'bn.js': function (fixture) {
198213
fixture.a1.toString(10);
199214
},
215+
BigInt: function (fixture) {
216+
fixture.a2.toString(10);
217+
},
200218
bignum: function (fixture) {
201219
fixture.a3.toString(10);
202220
},
@@ -215,6 +233,9 @@ add('toString-hex', {
215233
'bn.js': function (fixture) {
216234
fixture.a1.toString(16);
217235
},
236+
BigInt: function (fixture) {
237+
fixture.a2.toString(16);
238+
},
218239
bignum: function (fixture) {
219240
fixture.a3.toString(16);
220241
},
@@ -236,6 +257,9 @@ add('add', {
236257
'bn.js': function (fixture) {
237258
fixture.a1.add(fixture.b1);
238259
},
260+
BigInt: function (fixture) {
261+
fixture.a2 + fixture.b2;
262+
},
239263
bignum: function (fixture) {
240264
fixture.a3.add(fixture.b3);
241265
},
@@ -257,6 +281,9 @@ add('sub', {
257281
'bn.js': function (fixture) {
258282
fixture.b1.sub(fixture.a1);
259283
},
284+
BigInt: function (fixture) {
285+
fixture.a2 - fixture.b2;
286+
},
260287
bignum: function (fixture) {
261288
fixture.b3.sub(fixture.a3);
262289
},
@@ -281,6 +308,9 @@ add('mul', {
281308
'bn.js[FFT]': function (fixture) {
282309
fixture.a1.mulf(fixture.b1);
283310
},
311+
BigInt: function (fixture) {
312+
fixture.a2 * fixture.b2;
313+
},
284314
bignum: function (fixture) {
285315
fixture.a3.mul(fixture.b3);
286316
},
@@ -305,6 +335,9 @@ add('mul-jumbo', {
305335
'bn.js[FFT]': function (fixture) {
306336
fixture.a1j.mulf(fixture.b1j);
307337
},
338+
BigInt: function (fixture) {
339+
fixture.a2j * fixture.b2j;
340+
},
308341
bignum: function (fixture) {
309342
fixture.a3j.mul(fixture.b3j);
310343
},
@@ -326,6 +359,9 @@ add('sqr', {
326359
'bn.js': function (fixture) {
327360
fixture.a1.mul(fixture.a1);
328361
},
362+
BigInt: function (fixture) {
363+
fixture.a2 * fixture.a2;
364+
},
329365
bignum: function (fixture) {
330366
fixture.a3.mul(fixture.a3);
331367
},
@@ -347,6 +383,9 @@ add('div', {
347383
'bn.js': function (fixture) {
348384
fixture.as1.div(fixture.a1);
349385
},
386+
BigInt: function (fixture) {
387+
fixture.as2 / fixture.a2;
388+
},
350389
bignum: function (fixture) {
351390
fixture.as3.div(fixture.a3);
352391
},
@@ -365,6 +404,9 @@ add('mod', {
365404
'bn.js': function (fixture) {
366405
fixture.as1.mod(fixture.a1);
367406
},
407+
BigInt: function (fixture) {
408+
fixture.as2 / fixture.a2;
409+
},
368410
bignum: function (fixture) {
369411
fixture.as3.mod(fixture.a3);
370412
},

0 commit comments

Comments
 (0)