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

Revision 138 of this benchmark created by bluefireuoop on


Description

Rounding in all form possible

Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor
function a(m) {
  m.floor(89.938 / 293.3);
  m.floor(83784 / 9289.2);
  m.floor(7 / 60);
}
a(Math);
ready
Math.round
function a(m) {
  Math.round(89.938 / 293.3);
  Math.round(83784 / 9289.2);
  Math.round(7 / 60);
}
a(Math);
ready
parseInt
function a(m) {
  parseInt(89.938 / 293.3);
  parseInt(83784 / 9289.2);
  parseInt(7 / 60);
}
a();
ready
Bitwise |
function a(m) {
  89.938 / 293.3 | 0;
  83784 / 9289.2 | 0;
  7 / 60 | 0;
}
a();
ready
Bitwise >>
function a(m) {
  89.938 / 293.3 >> 0;
  83784 / 9289.2 >> 0;
  7 / 60 >> 0;
}
a();
ready
Bitwise ~~
function a(m) {~~
  (89.938 / 293.3);~~
  (83784 / 9289.2);~~
  (7 / 60);
}
a();
ready
Bitwise <<
function a(m) {
  89.938 / 293.3 << 0;
  83784 / 9289.2 << 0;
  7 / 60 << 0;
}
a();
ready

Revisions

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