Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Square root vs squared distance vs fastInvSqrt vs approx distance
(version: 1)
Comparing performance of:
Math.sqrt() vs squared distance
Created:
9 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var coords = []; for(let i = 0; i < 1000; i++) { coords[i] = [Math.random() * 100, Math.random() * 100]; } var gravity = 1.0, x, y, distance, force;
Tests:
Math.sqrt()
for(const coord of coords) { x = coords[0]; y = coords[1]; distance = Math.sqrt(x * x + y * y); force = gravity / (distance * distance); }
squared distance
for(const coord of coords) { x = coords[0]; y = coords[1]; distance = x * x + y * y; force = gravity / distance; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Math.sqrt()
squared distance
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Comments
Confirm delete:
Do you really want to delete benchmark?