Comparing custom and bult-in Math.round

Benchmark created on


Description

See: http://stackoverflow.com/q/8483357/1011582

Custom Math.round implementation is:

R1(a,b){var c=a%b;return a-c+(c/b+1.5>>1)*b}

Setup

function R1(a,b){var c=a%b;return a-c+(c/b+1.5>>1)*b}
    R2 = Math.round;
    function R3 (a) { return Math.round(a) }

Test runner

Ready to run.

Testing in
TestOps/sec
Custom Math.round
R1(3.5,1);
ready
Built-in Math.round
R2(3.5);
ready
Built-in Math.round inside function
R3(3.5);
ready

Revisions

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