Math.round vs hack (v94)

Revision 94 of this benchmark created by afaf on


Preparation HTML

<script>
  var somenum = -500 + (Math.random() * 1000);
  var rounded;
</script>

Setup

function round(a){
    var b=a|0;
    return a-b<.5?b:b+1;
  }

Test runner

Ready to run.

Testing in
TestOps/sec
"proper" rounding
Math.round(4.6253256533);
Math.round(19345.361612);
ready
Hack rounding
round(4.6253256533);
round(19345.361612);
ready

Revisions

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