Distance check: Pythagoras vs Simple delta X delta Y (v3)

Revision 3 of this benchmark created on


Description

Comparison of true distance (Pythagoras) limit check between points vs just checking distance of X and Y separately.

Preparation HTML

<script>
  var x1 = 4;
  var x2 = 200;
  var y1 = 5;
  var y2 = 102;
  
  var limit = 195;
  var limitSquere = limit * limit ;
  var limit2 = 10;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Pythagoras
(Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2))) < limit;
ready
Delta X & Delta Y
Math.abs(x1 - x2) < limit && Math.abs(y1 - y2) < limit;
ready
Delta ||
!(Math.abs(x1 - x2) > limit || Math.abs(y1 - y2) > limit);
ready
Single delta
Math.abs(x1 - x2) > limit
ready
Pythagoras 2
(Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2))) < limit2;
ready
Single delta 2
(x1 > x2 ? x1 - x2 : x2 - x1) > limit
ready
Delta || 2
!((x1 > x2 ? x1 - x2 : x2 - x1) > limit || (y1 > y2 ? y1 - y2 : y2 - y1) > limit);
ready
Pythagoras - no pow
var dx = x1 - x2;
var dy = y1 - y2;
(Math.sqrt(dx * dx + dy * dy)) < limit;
ready
Pythagoras - no pow and sqrt
var dx = x1 - x2;
var dy = y1 - y2;
dx * dx + dy * dy < limit * limit;
ready
Pythagoras - no pow and sqrt alt
var dx = x1 - x2;
var dy = y1 - y2;
dx * dx + dy * dy < limitSquere;
ready

Revisions

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