Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
pointDistance vs rectDistance
he
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser:
Chrome 126
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
pointDistance
7.2 Ops/sec
rectDistance
19.3 Ops/sec
Script Preparation code:
function pointDistance( fromX, fromY, toX, toY, ) { const diffX = toX - fromX; const diffY = toY - fromY; const distance = Math.sqrt(diffX ** 2 + diffY ** 2); return [distance, diffX / distance, diffY / distance]; } function rectDistance(xA, yA, radiusA, xB, yB, radiusB) { const leftA = xA - radiusA; const rightA = xA + radiusA; const topA = yA - radiusA; const bottomA = yA + radiusA; const leftB = xB - radiusB; const rightB = xB + radiusB; const topB = yB - radiusB; const bottomB = yB + radiusB; const xDistance = leftB > rightA ? leftB - rightA : leftA > rightB ? leftA - rightB : 0; const yDistance = topB > bottomA ? topB - bottomA : topA > bottomB ? topA - bottomB : 0; return xDistance > yDistance ? xDistance : yDistance; }
Tests:
pointDistance
for (let i = 0, len = 1_000_000; i < len; i++) { const d = pointDistance(i + 1.5, i + 2.5, i + 3.5, i + 4.5); }
rectDistance
for (let i = 0, len = 1_000_000; i < len; i++) { const d = rectDistance(i + 1.5, i + 2.5, 4, i + 3.5, i + 4.5, 5); }