Skip to content

Instantly share code, notes, and snippets.

@tlivings
Last active August 29, 2015 14:00
Show Gist options
  • Save tlivings/11327317 to your computer and use it in GitHub Desktop.
Save tlivings/11327317 to your computer and use it in GitHub Desktop.
bignum vs bn.js
var anvil = require('anvil'),
bignum = require('bignum'),
bn = require('bn.js');
anvil('Bignum functions', function (forge, hammer) {
var bigBuffer, bigString;
bigBuffer = new Buffer([ 24, 7, 144, 87, 61, 194, 2, 7 ]);
bigString = '1731511286119924231';
forge.after(function (error, results) {
results.forEach(function (report) {
console.log('%s: %d operations/second.', report.name, report.ops);
});
});
forge.add('bignum to buffer', function () {
bignum(bigString).toBuffer();
});
forge.add('bn to array', function () {
new bn(bigString).toArray();
});
forge.add('bignum from buffer', function () {
bignum.fromBuffer(bigBuffer);
});
forge.add('bn from buffer', function () {
new bn(bigBuffer);
});
forge.add('bignum from buffer toString', function () {
bignum.fromBuffer(bigBuffer).toString();
});
forge.add('bn from buffer toString', function () {
new bn(bigBuffer).toString();
});
hammer();
});
bignum to buffer: 33910 operations/second.
bn to array: 40950 operations/second.
bignum from buffer: 128041 operations/second.
bn from buffer: 1000000 operations/second.
bignum from buffer toString: 90334 operations/second.
bn from buffer toString: 12151 operations/second.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment