Skip to content

Instantly share code, notes, and snippets.

@kdimatteo
Last active February 17, 2017 12:02
Show Gist options
  • Save kdimatteo/8228162 to your computer and use it in GitHub Desktop.
Save kdimatteo/8228162 to your computer and use it in GitHub Desktop.
JS Math.fastCeil for performance
/**
* 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)
};
@stefnotch
Copy link

Now it seems to be slower than Math.ceil()
Tested in: Firefox 51 and in Chrome 50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment