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;
// ]]>
</script>
      
<script>
Benchmark.prototype.setup = function() {
  const floor = Math.floor;

};
</script>

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
Math.floor(number)
for( let number of numbers ) floor(number);
pending…

Revisions

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

0 Comments