Run details:
Mozilla/5.0 (iPhone; CPU iPhone OS 16_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/119.0.6045.169 Mobile/15E148 Safari/604.1
Chrome Mobile iOS 119
iOS 16.7
Mobile
one year ago
Test name Executions per second
1 / Math.sqrt() 8578.1 Ops/sec
Fast inverse sqrt 9426.4 Ops/sec
Script Preparation code:
x
 
let v = 123.75;
function test1() {
  let r;
  for(let i = 0; i < 2000; ++i)
    r = 1 / Math.sqrt(v);
}
function test2() {
  let r;
  for(let i = 0; i < 2000; ++i)
    r = Q_sqrt(v);
}
function Q_sqrt(num) {
  let i = [];
  let y = [];
  
  y[0] = num;
  i[0] = 0x5f375a86 - (i[0] >> 1);
  
  y[0] = y[0] * (1.5 * ((num * 0.5) * y[0] * y[0]));
  
  return y[0];
}
Tests:
  • 1 / Math.sqrt()

     
    test1();
  • Fast inverse sqrt

     
    test2();