Last active
February 17, 2017 12:02
-
-
Save kdimatteo/8228162 to your computer and use it in GitHub Desktop.
JS Math.fastCeil for performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 90% faster that native Math.ceil() | |
* http://jsperf.com/math-ceil-v-math-fastceil | |
*/ | |
Math.fastCeil = function (n) { | |
var t = ~~n; | |
return t === n ? n : (n > 0) ? (t + 1) : (t - 1) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now it seems to be slower than Math.ceil()
Tested in: Firefox 51 and in Chrome 50