Multiplication (int) vs Bit-Shifting (left) (v2)

Revision 2 of this benchmark created by Tim on


Description

A friend of mine was pretty excited to learn that there are possible speed increases associated with shifting bits over the multiplication operator, or by using multiplication over the division operator. However, I wonder if a good compiler or interpreter wouldn't make these optimization choices for you! Let's find out with JS!

Test runner

Ready to run.

Testing in
TestOps/sec
Multiplication (int)
(function(){return 10 * 2})();
(function(){return 10 * 4})();
(function(){return 10 * 8})();
ready
Bit-Shifting (left)
(function(){return 10 << 1})();
(function(){return 10 << 2})();
(function(){return 10 << 3})();
ready
Division Operator
(function(){return 10 / 2})();
(function(){return 10 / 4})();
(function(){return 10 / 8})();
ready
Division through Multiplying by a Float
(function(){return 10 * 0.5})();
(function(){return 10 * 0.25})();
(function(){return 10 * 0.125})();
ready
Division through bit-shifting right.
(function(){return 10 >> 1})();
(function(){return 10 >> 2})();
(function(){return 10 >> 3})();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.