Math.abs-vs-bitwise (v16)

Revision 16 of this benchmark created on


Description

Checking performance differences between Math.abs and using Bitwise manipulation.

Preparation HTML

<script>
  var nums = [];
  
  for (var i = 0; i < 200; i++) {
   nums.push(Math.random() * 100);
  }
  
  function abs(x) {
   return (x < 0 ? -x : x);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Math.abs()
var o,
localAbs = Math.abs;

for (var i = 0; i < 200; i++) {
 o = localAbs(nums[i]);
}
ready
bitwise
var o;

for (var i = 0; i < 200; i++) {
 o = abs(nums[i]);
}
ready

Revisions

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