`Math.hypot` versus manual length (v4)

Revision 4 of this benchmark created on


Description

Compares the built-in Math.hypot function with manual two-dimensional length calculation.

Setup

const a = Math.floor(Math.random() * 100);
const b = Math.floor(Math.random() * 100);

Test runner

Ready to run.

Testing in
TestOps/sec
`Math.hypot`
Math.hypot(a, b);
ready
Manual (multiplication operator)
Math.sqrt(a * a + b * b);
ready
Manual (exponentiation operator)
Math.sqrt(a ** 2 + b ** 2);
ready
Manual (`Math.pow`)
Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
ready

Revisions

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