Math.floor vs ~~ vs >> 0

Benchmark created on


Description

Integer division

Setup

const floor = (num, den) => {
	return Math.floor(num / den);
};
const tilde = (num, den) => {
	return ~~(num / den);
};
const gtgtz = (num, den) => {
	return (num / den) >> 0;
};
const pipez = (num, den) => {
	return (num / den|0);
};
const remin = (num, den) => {
	return (num - (num % den))/ den;
};

Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor
floor(1005, 100);
ready
Double Tilde
tilde(1005, 100);
ready
Bitshift
gtgtz(1005, 10)
ready
Pipe Zero
pipez(1005, 10);
ready
Remainder Subtraction
remin(1005, 10);
ready

Revisions

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