Test name | Executions per second |
---|---|
1 / Math.sqrt() | 8578.1 Ops/sec |
Fast inverse sqrt | 9426.4 Ops/sec |
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];
}
test1();
test2();