Absolute value speed

JavaScript performance comparison

Revision 9 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function tern(n){
  return n < 0 ? -n : n;
  }
  
  function bit_1(n){
  return (n >>> 31) ? n ^ -1 : n;
  }
  
  function bit_2(n){
  return (n >>> 31) ? -n : n;
  }
  
  function bit_3(n){
  return (n >>> 31) ? n ^ -1 : n;
  }

};

Benchmark.prototype.teardown = function() {
  var a = 2.73, b = -3.51, c = 0
  var i;

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Math
i = Math.abs(a);
i = Math.abs(b);
i = Math.abs(c);
pending…
Ternary
i = tern(a);
i = tern(b);
i = tern(c);
pending…
Bitwise 1
i = bit_1(a);
i = bit_1(b);
i = bit_1(c);
pending…
Bitwise 2
i = bit_2(a);
i = bit_2(b);
i = bit_2(c);
pending…
Bitwise 3
i = bit_3(a);
i = bit_3(b);
i = bit_3(c);
pending…

Compare results of other browsers

Revisions

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

0 Comments