Math.round vs 0

JavaScript performance comparison

Test case created by Joshua Kehn


Compare Math.round with a bitwise operator.

Preparation code

  var a = 109939,
      b = 329;

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
var c = Math.round(a / b);
var c = a / b | 0;

Compare results of other browsers


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.

Comment form temporarily disabled.

Add a comment