Math.floor vs Math.round vs parseInt vs Bitwise

JavaScript performance comparison

Revision 99 of this test case created

Info

Rounding in all form possible

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var num = Math.random() * 255 * 255
};
</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
Math.floor
Math.floor(num);
pending…
Math.round
Math.round(num);
pending…
parseInt
parseInt(num,10);
pending…
Bitwise |
num | 0;
pending…
Bitwise
num >> 1;
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