Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
LatLongDistance
(version: 0)
Comparing performance of:
full vs quick
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function getDistanceFromLatLonInKm2(lat, lng, lat0, lng0) { //https://jonisalonen.com/2014/computing-distance-between-coordinates-can-be-simple-and-fast/ let deglen = 110.25 let x = lat - lat0 let y = (lng - lng0)*Math.cos(lat0) return deglen*Math.sqrt(x*x + y*y) } function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) { var R = 6371; // Radius of the earth in km var dLat = deg2rad(lat2-lat1); // deg2rad below var dLon = deg2rad(lon2-lon1); var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon/2) * Math.sin(dLon/2) ; var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); var d = R * c; // Distance in km return d; } function deg2rad(deg) { return deg * (Math.PI/180) }
Tests:
full
getDistanceFromLatLonInKm(51.496, -0.143, 51.601, -0.118);
quick
getDistanceFromLatLonInKm2(51.496, -0.143, 51.601, -0.118);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
full
quick
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!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its various components. **Benchmark Definition** The provided JSON defines two benchmark functions: `getDistanceFromLatLonInKm` and `getDistanceFromLatLonInKm2`. Both functions calculate the distance between two points on the Earth's surface using the Haversine formula. The main difference between the two functions is that `getDistanceFromLatLonInKm2` uses a simpler, more straightforward approach to calculate the distance. **Options Compared** The benchmark compares two options: 1. `getDistanceFromLatLonInKm`: This function uses the Haversine formula, which takes into account the Earth's radius and the latitude and longitude differences between the two points. 2. `getDistanceFromLatLonInKm2`: This function uses a simplified version of the Haversine formula, which is faster but may not be as accurate. **Pros and Cons** * `getDistanceFromLatLonInKm`: + Pros: More accurate results + Cons: Slower performance due to the more complex calculation * `getDistanceFromLatLonInKm2`: + Pros: Faster performance, potentially suitable for low-latency applications + Cons: May produce less accurate results **Library and Purpose** There is no explicit library mentioned in the benchmark definition. However, it's likely that the functions use built-in JavaScript functionality, such as trigonometric functions (e.g., `Math.sin`, `Math.cos`) and mathematical constants (e.g., π). **Special JS Feature or Syntax** There are no special features or syntaxes used in this benchmark. **Other Considerations** * The benchmark assumes that the input coordinates are in degrees and the Earth's radius is 6371 km. * The `deg2rad` function converts degrees to radians, which is used in the Haversine formula. * The benchmark uses Safari as the target browser, with a specific version and platform. **Alternative Approaches** Other approaches to calculate the distance between two points on the Earth's surface include: 1. Using a geodesic calculation method, such as the Vincenty formula, which is more accurate but also more complex. 2. Using a third-party library or service that provides pre-calculated distances for common latitude and longitude pairs. 3. Using a different algorithm or data structure to represent the Earth's surface, such as a spherical harmonics representation. In summary, the benchmark compares two options for calculating the distance between two points on the Earth's surface: `getDistanceFromLatLonInKm` (more accurate) vs. `getDistanceFromLatLonInKm2` (faster). The choice of approach depends on the specific requirements of the application, such as accuracy, performance, and complexity.
Related benchmarks:
Haversine Distance tests
Geo distance
Geo distance 2
pointDistance vs rectDistance
Comments
Confirm delete:
Do you really want to delete benchmark?