Rounding numbers down

JavaScript performance comparison

Test case created by Mathias Bynens and last updated

Preparation code

<script>
  var n = Math.PI; // 3.141592653589793
</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
Math.floor(n); // 3
pending…
parseInt
parseInt(n, 10); // 3
pending…
Double bitwise NOT
~~n; // 3
pending…
Bitwise OR
n | n; // 3
pending…
Bitwise OR with 0
n | 0; // 3
pending…
Bitwise left shift
n << 0; // 3
pending…
Bitwise AND
n & n; // 3
pending…

Compare results of other browsers

Revisions

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

0 Comments