abs

Benchmark created on


Setup

const mathAbs = Math.abs;
function bitAbs(x) {
  return (x ^ (x >> 31)) - (x >> 31)
}

function bitAbs2(x) {
  const mask = x >> 31;
  return (x ^ mask) - mask;
}

Test runner

Ready to run.

Testing in
TestOps/sec
math.abs
for (let i = 0; i < 50; i++){
	mathAbs(50/i)
}
ready
bitwise abs
for (let i = 0; i < 50; i++){
	bitAbs(50/i)
}
ready
bitAbs2 abs
for (let i = 0; i < 50; i++){
	bitAbs2(50/i)
}
ready

Revisions

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