floorlog2

Benchmark created on


Setup

function l( x ) {
    let y = 0;
    while ( x > 1 ) {

        y += 1;
        x >>= 1;

    }
    return y;
}

function l2( x ) {
    return Math.floor( Math.log2(x) );
}

function l3( x ) {
    return 31 - Math.clz32( x );
}

Test runner

Ready to run.

Testing in
TestOps/sec
exr
for ( let i = 0; i < 1024; i++ ) l(i);
ready
js
for ( let i = 0; i < 1024; i++ ) l2(i);
ready
clz
for ( let i = 0; i < 1024; i++ ) l3(i);
ready

Revisions

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