Skip to content

Instantly share code, notes, and snippets.

@indutny

indutny/bench.js Secret

Last active October 31, 2016 00:28
Show Gist options
  • Save indutny/f37c466b4765e686b766b0b32557557c to your computer and use it in GitHub Desktop.
Save indutny/f37c466b4765e686b766b0b32557557c to your computer and use it in GitHub Desktop.
var BN = require('./');
function fill(num, storage) {
num.words = storage;
num.length = storage.length;
for (var i = 0; i < storage.length; i++)
num.words[i] = 0x3ffffff ^ i;
}
function bench(A, B, C) {
console.log(A.constructor.name);
const a = new BN(null);
const b = new BN(null);
const c = new BN(null);
fill(a, A);
fill(b, B);
fill(c, C);
const start = process.hrtime();
for (var i = 0; i < 1e6; i++)
a.mulTo(b, c);
const delta = process.hrtime(start);
console.log(delta);
}
if (process.argv[2] === 'u')
bench(new Uint32Array(8), new Uint32Array(8), new Uint32Array(8));
else
bench(new Array(8), new Array(8), new Array(8));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment