Math.floor vs bitwise ops

JavaScript performance comparison

Revision 5 of this test case created by Nicolas HENRY

Preparation code

<script type="text/javascript">
// <![CDATA[
 * Testing speed difference between Math.floor() and bitwise operations.
 * Bitwise operations convert the input float number into an integer internally and then convert it back to float for the result.
    var numbers = Array(1E3), i = 0;
    for( ; i < 1E3 ; i++ ) numbers[i] = Math.random() * 100;
// ]]>
Benchmark.prototype.setup = function() {
  const floor = Math.floor;


Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
for( let number of numbers ) floor(number);


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