Comparing custom and bult-in Math.round

JavaScript performance comparison

Test case created

Info

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}

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    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) }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Custom Math.round
R1(3.5,1);
pending…
Built-in Math.round
R2(3.5);
pending…
Built-in Math.round inside function
R3(3.5);
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. Here’s a list of current revisions for this page:

0 comments

Add a comment