Last Updated: February 25, 2016
·
1.275K
· thomaslindstr_m

Use bitwise instead of Math-functions in JavaScript

For a quick and simple performance boost, use bitwise instead of the Math-functions in JavaScript.

Take a look for yourself: http://jsperf.com/bitwise-compares

On my iPhone 4, using bitwise is a staggering 60 times faster, and on the high-end Samsung Galaxy s3, it's over 70 times faster.

Math.floor(123.123)

is the same as

123.123 << 0

and

Math.round(123.123)

can be done like this

(0.5+123.123) << 0

Now go out there and increase your app's performance tenfold!