Hypot vs Sqrt (v2)

Revision 2 of this benchmark created on


Setup

let total = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
sqrt
total = 0;
for(let i = 0; i < 1000; i++) {
	let x = Math.random();
	let y = Math.random();
	total += Math.sqrt(x * x + y * y);
}
ready
hypot
total = 0;
for(let i = 0; i < 1000; i++) {
	let x = Math.random();
	let y = Math.random();
	total += Math.hypot(x, y);
}
ready
sqrt (pow operator)
total = 0;
for(let i = 0; i < 1000; i++) {
	let x = Math.random();
	let y = Math.random();
	total += (x ** 2 + y ** 2) ** 0.5;
}
ready

Revisions

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