BigInt vs. number operations (v8)

Revision 8 of this benchmark created on


Setup

let sp = 100000;

const numbers = new Int32Array(sp);

for (let i = 0; i < sp; i++) {
	numbers[i] = (Math.random() * 0x100000000) & 0xffffffff;
}

const ints = new BigInt64Array([...numbers].map((x) => BigInt(x)));

const operations = [
	(a, b) => a + b,
	(a, b) => a - b,
	(a, b) => a * b,
	(a, b) => b == 0 ? b : a / b,
	(a, b) => b == 0 ? b : a % b,
];

let op = 0;

function popNumber() {
	return numbers[--sp];
}

function pushNumber(number) {
	numbers[++sp] = number;
}

function popInt() {
	return ints[--sp];
}

function pushInt(int) {
	ints[++sp] = int;
}

Test runner

Ready to run.

Testing in
TestOps/sec
number
sp = numbers.length;

while (sp >= 2) {
	pushNumber(operations[op](popNumber(), popNumber()));
	++op;
	op %= 5;
}
ready
BigInt
sp = ints.length;

while (sp >= 2) {
	pushInt(operations[op](popInt(), popInt()));
	++op;
	op %= 5;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.