BigInt vs. number operations

Benchmark created on


Setup

const numbers = [];

for (let i = 0; i < 100000; i++) {
	numbers.push((Math.random() * 0xffffffff) & 0xffffffff);
}

const ints = numbers.map((x) => BigInt(x));

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

const program = Array.from({ length: numbers.length - 1 }, () => (Math.random() * operations.length) | 0);

console.log("e");

Test runner

Ready to run.

Testing in
TestOps/sec
number
for (const op of program) {
	numbers.push(operations[op](numbers.pop(), numbers.pop()) & 0xffffffff);
}

console.log(numbers.pop());
ready
BigInt
for (const op of program) {
	ints.push(BigInt(Number(operations[op](ints.pop(), ints.pop())) & 0xffffffff));
}

console.log(ints.pop());
ready

Revisions

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