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!
Written by Thomas Lindstrøm
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Performance
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#