log base 2 (v2)

Revision 2 of this benchmark created on


Description

How fast is the table lookup doing log base 2?

Setup

function log(a) {
      return Math.log(a) / Math.log(2)
    };
    var table = [0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9];
    
    function lookup(a) {
      return table[(a & -a) * 0x077CB531 >>> 27]
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Log
for (var i = 2147483648; log(i >>>= 1););
ready
Lookup
for (var i = 2147483648; lookup(i >>>= 1););
ready

Revisions

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