Math.round vs 0

JavaScript performance comparison

Test case created by Joshua Kehn

Info

Compare Math.round with a bitwise operator.

Preparation code

<script>
  var a = 109939,
      b = 329;
</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.round
var c = Math.round(a / b);
pending…
Bitwise
var c = a / b | 0;
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:

1 comment

rolandog commented :

These aren't the same tests, you should change the test to compare parseInt since Math.round(4.6) returns 5, and 4.6 | 0 returns 4.

Add a comment