sqrt vs fast inverse sqrt (v8)

Revision 8 of this benchmark created on


Setup

var y = new Float32Array(1);
    var i = new Int32Array(y.buffer);
    var fastInvSqrt_typed = function(n) {
      var n2 = n * 0.5;
      y[0] = n;
      i[0] = 0x5f375a86 - (i[0] >> 1);
      n = y[0];
      return n * (1.5 - (n2 * n * n));
    };
    var random = Math.random;
    var sqrt = Math.sqrt;

Test runner

Ready to run.

Testing in
TestOps/sec
Math.sqrt
1/Math.sqrt(random());
ready
cached Math.sqrt
1/sqrt(random());
ready
Pow 0.5
Math.pow(random(),-0.5);
ready
fast inverse sqrt
fastInvSqrt_typed(random());
ready

Revisions

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