Inverse Square Root (v2)

Revision 2 of this benchmark created on


Description

A Flash and C trick ported to JS array buffers. Doesn't look like a gain yet.

Preparation HTML

<script>
  var x = Math.random();
  var Math_sqrt = Math.sqrt;
  var buffer = new ArrayBuffer(4);
  var int32 = new Int32Array(buffer);
  var float32 = new Float32Array(buffer);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Classic
for (var i = 0; i < 100; i++) {
 var result = 1.0 / Math_sqrt(Math.random() * 1000);
}
ready
Quake inverse sqrt
for (var i = 0; i < 100; i++) {
 float32[0] = Math.random() * 1000;
 int32[0] = 0x5f3759df - (int32[0] >> 1);
 var result = float32[0];
 result *= (1.5 - 0.5 * x * result * result);
}
ready

Revisions

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