tilde vs floor vs others

JavaScript performance comparison

Revision 7 of this test case created

Info

Comparison between ~~ and Math.floor, bitwise or with zero, shift, modulo operator, parseInt.

Preparation code

<script>
  var x = 3.14;
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
tildes
var y = ~~x;
pending…
floor
var y = Math.floor(x);
pending…
modulo
var y = x - x % 1;
pending…
parseInt
var y = parseInt(x,10);
pending…
shift
var y = x >> 0;
pending…
or
var y = x | 0;
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. Here’s a list of current revisions for this page:

0 comments

Add a comment