Absolute value speed (v3)

Revision 3 of this benchmark created by Solenoid on


Setup

function abs(n){
    return n < 0 ? -n : n;
    }
    
    function abs2(n){
    return (n^(n>>31))-(n>>31);
    }

Teardown


    var a = 2, b = -3, c = 0
  

Test runner

Ready to run.

Testing in
TestOps/sec
Math
Math.abs(a);
Math.abs(b);
Math.abs(c);
ready
Function
abs(a);
abs(b);
abs(c);
ready
Bitwise
abs2(a);
abs2(b);
abs2(c);
ready

Revisions

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