Why is Javascript's Math.floor the slowest way to calculate floor in Javascript?

Posted by z5h on Stack Overflow See other posts from Stack Overflow or by z5h
Published on 2010-03-26T20:55:28Z Indexed on 2010/03/26 21:03 UTC
Read the original article Hit count: 235

Filed under:
|

I'm generally not a fan of microbenchmarks. But this one has a very interesting result.
http://ernestdelgado.com/archive/benchmark-on-the-floor/

It suggests that Math.floor is the SLOWEST way to calculate floor in Javascript. ~~n, n|n, n&n all being faster.
This seems pretty shocking as I would expect that people implementing Javascript in today's modern browsers would be some pretty smart people.

Does floor do something important that the other methods fail to do? Is there any reason to use it?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about optimization