Division vs bit right shift (v10)

Revision 10 of this benchmark created on


Description

Right shift one mask is same as divide by 2 on integers. A right shift operation is much faster than a division op. Most static compilers do this optimization.

Setup

var x = 100;
    var y = 100;

Test runner

Ready to run.

Testing in
TestOps/sec
Division
x = y / 2;
y = x / 2;
ready
Right shift
x = y >> 1;
y = x >> 1;
ready
Best Ever
x = 50;
y = 25;
ready
Zero-fill right shift
x = y >>> 1;
y = x >>> 1;
ready
Math.pow
x = Math.pow(y,.85)|0;
x = Math.pow(x,.85)|0;
ready
Multiply
x = y * 0.5;
y = x * 0.5;
ready
Divide by 3!?
x = y / 3;
y = x / 3;
ready
Divide by 2 with floor
x = Math.floor(y/2);
y = Math.floor(x/2);
ready

Revisions

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