Script Preparation code:
AخA
 
const hypotTable = [];
for(let i = 0; i < 10000; i++) {
  hypotTable[i] = Math.sqrt(i);
}
function hypotLookup(i) {
  return hypotTable[i];
}
Tests:
  • Math.sqrt()

     
    const RAD_PER_DEG = Math.PI / 180;
    for(let i = 0; i < 360; i += 0.1) {
      const r = i * RAD_PER_DEG;
      const d = (100 / 360) * i;
      const x = Math.sin(r) * d;
      const y = Math.cos(r) * d;
      const s = Math.sqrt(x * x + y * y);
    }
  • Alpha max plus beta min

     
    const ALPHA = 0.96043387010342;
    const BETA = 0.397824734759316;
    const RAD_PER_DEG = Math.PI / 180;
    for(let i = 0; i < 360; i += 0.1) {
      const r = i * RAD_PER_DEG;
      const d = (100 / 360) * i;
      const x = Math.abs(Math.sin(r) * d);
      const y = Math.abs(Math.cos(r) * d);
      const h = x > y ? ALPHA*x + BETA*y : ALPHA*y + BETA*x;
    }
  • Lookup table

     
    const RAD_PER_DEG = Math.PI / 180;
    for(let i = 0; i < 360; i += 0.1) {
      const r = i * RAD_PER_DEG;
      const d = (100 / 360) * i;
      const x = Math.sin(r) * d;
      const y = Math.cos(r) * d;
      const h = hypotLookup(Math.floor(x * x + y * y));
    }
  • ** 0.5

     
    const RAD_PER_DEG = Math.PI / 180;
    for(let i = 0; i < 360; i += 0.1) {
      const r = i * RAD_PER_DEG;
      const d = (100 / 360) * i;
      const x = Math.sin(r) * d;
      const y = Math.cos(r) * d;
      const s = (x * x + y * y) ** 0.5;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Math.sqrt()
    Alpha max plus beta min
    Lookup table
    ** 0.5

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Safari/605.1.15
Safari 15 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Math.sqrt() 1670.4 Ops/sec
Alpha max plus beta min 1252.1 Ops/sec
Lookup table 1356.0 Ops/sec
** 0.5 2372.7 Ops/sec