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

Revision 13 of this benchmark created 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)
10 * 2;
10 * 4;
10 * 8;
ready
Bit-Shifting (left)
10 << 1;
10 << 2;
10 << 3;
ready
Division Operator
10 / 2;
10 / 4;
10 / 8;
ready
Division through Multiplying by a Float
10 * 0.5;
10 * 0.25;
10 * 0.125;
ready
Division through bit-shifting right.
10 >> 1;
10 >> 2;
10 >> 3;
ready

Revisions

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