Math.floor vs shift

JavaScript performance comparison

Test case created by Ted Hopp

Info

Compares Math.floor(x) to (x >> 0) as a way of converting to an int. They aren't completely equivalent; note that Math.floor(NaN) is NaN, while (NaN >> 0) is 0.

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Math.floor
var x = Math.floor(1.5);
pending…
Shift
var x = (1.5 >> 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