Rounding numbers down (v4)

Revision 4 of this benchmark created on


Preparation HTML

<script>
  var n = Math.PI, // 3.141592653589793
      substr = String.prototype.substr,
      split = String.prototype.split,
      indexOf = String.prototype.indexOf;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor
Math.floor(n); // 3
ready
parseInt
parseInt(n, 10); // 3
ready
Double bitwise NOT
~~n; // 3
ready
Bitwise OR
n | n; // 3
ready
Bitwise OR with 0
n | 0; // 3
ready
Bitwise AND
n & n; // 3
ready
Bitwise left shift
n << 0; // 3
ready
toString, split, and toNumber
('' + n).split('.')[0] * 1; // 3
ready
String.prototype.substr and indexOf with conversion
+String.prototype.substr.call(n, 0, String.prototype.indexOf.call(n, '.', 0)); // 3
ready
Cached String.prototype.substr
+substr.call(n, 0, indexOf.call(n, '.', 0)); // 3
ready
String.prototype.split
+String.prototype.split.call(n, '.')[0]; // 3
ready
Cached String.prototype.split
+split.call(n, '.')[0]; // 3
ready
Bitwise right shift
n >> 0; // 3
ready
Bitwise zero-fill right shift
n >>> 0; // 3
ready

Revisions

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