Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:136.0) Gecko/20100101 Firefox/136.0
Firefox 136
Windows
Desktop
8 days ago
Test name Executions per second
sqrt 32.0 Ops/sec
sqrt * direct 32.7 Ops/sec
hypot 31.9 Ops/sec
Script Preparation code:
AخA
 
const N = 1e7;
const values = new Array(N).fill(0).map(() => [Math.random(), Math.random()]);
Tests:
  • sqrt

     
    for (let i = 0; i < N; i++) {
        Math.sqrt(values[i][0] ** 2 + values[i][1] ** 2);
    }
  • sqrt * direct

     
    for (let i = 0; i < N; i++) {
        Math.sqrt(values[i][0] * values[i][0] + values[i][1] * values[i][1]);
    }
  • hypot

     
    for (let i = 0; i < N; i++) {
        Math.hypot(values[i][0], values[i][1]);
    }