Comparing custom and bult-in Math.round (v3)

Revision 3 of this 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)
    }
    
    tally = 0

Test runner

Ready to run.

Testing in
TestOps/sec
Custom Math.round
tally += R1(tally, 1);
ready
Built-in Math.round (direct)
tally += R2(tally);
ready
Built-in Math.round (wrapped)
tally += R3(tally);
ready
Custom Math.round #OPT
R1(Math.random(), 1)
ready
Built-in Math.round (direct) #OPT
R2(Math.random())
ready
Built-in Math.round (wrapped) #OPT
R3(Math.random())
ready

Revisions

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