Math.floor vs Math.round vs parseInt vs Bitwise (v115)

Revision 115 of this benchmark created by Aicke Schulz on


Description

  1. Real rounding by adding 0.5, no fake rounding like all the others do
  2. use base 10 for parseInt(), thats the most common case to parse ints, so the results are more realistic (btw. the result by about 5-10%)

Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor
Math.floor(89.938 / 293.3 + 0.5);
Math.floor(83784 / 9289.2 + 0.5);
Math.floor(7 / 60 + 0.5);
ready
Math.round
Math.round(89.938 / 293.3);
Math.round(83784 / 9289.2);
Math.round(7 / 60);
ready
parseInt
parseInt(89.938 / 293.3 + 0.5, 10);
parseInt(83784 / 9289.2 + 0.5, 10);
parseInt(7 / 60 + 0.5, 10);
ready
Bitwise |
(89.938 / 293.3 + 0.5) | 0;
(83784 / 9289.2 + 0.5) | 0;
(7 / 60 + 0.5) | 0;
ready
Bitwise
(89.938 / 293.3 + 0.5) >> 1;
(83784 / 9289.2 + 0.5) >> 1;
(7 / 60 + 0.5) >> 1;
ready

Revisions

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