Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Haversine
(version: 0)
Comparing performance of:
Distance1 vs Distance2 vs Distance3 vs Distance4 vs Distance5 vs Distance6
Created:
9 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var TO_RAD = Math.PI / 180; function toRad(deg) { return deg * TO_RAD; } var coords = new Array(); function randomLat() { return Math.random() * 180 - 90; } function randomLong() { return Math.random() * 360 - 180; } for (var i = 0; i < 5000; i++) { coords.push([randomLat(), randomLong(), randomLat(), randomLong()]); } function compute(coord, f) { return f(coord[0], coord[1], coord[2], coord[3]); } function test(f) { for (var i = 0; i < coords.length; i++) { var coord = coords[i]; compute(coord, f); } } var R = 6371009; // m var R2 = 6371009 * 2; // m function distance1(lat1, lon1, lat2, lon2) { var R = 6371009; // m var dLat = toRad(lat2 - lat1); var dLon = toRad(lon2 - lon1); var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return R * c; } function distance2(lat1, lon1, lat2, lon2) { var aLat = toRad(lat1); var bLat = toRad(lat2); var dLat2 = (bLat - aLat) / 2; var dLon2 = toRad(lon2 - lon1) / 2; var x = Math.sin(dLat2) * Math.sin(dLat2) + Math.cos(aLat) * Math.cos(bLat) * Math.sin(dLon2) * Math.sin(dLon2); return R * 2 * Math.atan2(Math.sqrt(x), Math.sqrt(1 - x)); } function distance3(lat1, lon1, lat2, lon2) { var aLat = toRad(lat1); var bLat = toRad(lat2); var dLat2 = (bLat - aLat) * 0.5; var dLon2 = toRad(lon2 - lon1) * 0.5; var sindLat = Math.sin(dLat2); var sindLon = Math.sin(dLon2); var x = sindLat * sindLat + Math.cos(aLat) * Math.cos(bLat) * sindLon * sindLon; return R2 * Math.atan2(Math.sqrt(x), Math.sqrt(1 - x)); } function getDistance(lat1, lon1, lat2, lon2) { const TO_RAD2 = Math.PI / 180; lat1 = lat1 * TO_RAD2; lat2 = lat2 * TO_RAD2; var sinDeltaLat = (lat2 - lat1) * 0.5; var sinDeltaLon = (lon2 - lon1) * TO_RAD2 * 0.5; var a = sinDeltaLat * sinDeltaLat + Math.cos(lat1) * Math.cos(lat2) * sinDeltaLon * sinDeltaLon; // Return distance in meters return 12742000 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); } function distance4(lat1, lon1, lat2, lon2) { var aLat = lat1 * TO_RAD; var bLat = lat2 * TO_RAD; var dLat2 = (bLat - aLat) * 0.5; var dLon2 = (lon2 - lon1) * TO_RAD * 0.5; var sindLat = Math.sin(dLat2); var sindLon = Math.sin(dLon2); var x = sindLat * sindLat + Math.cos(aLat) * Math.cos(bLat) * sindLon * sindLon; return R2 * Math.atan2(Math.sqrt(x), Math.sqrt(1 - x)); } function distance5(lat1, lon1, lat2, lon2) { var R = 6371009; // m var dLat = toRad(lat2 - lat1); var dLon = toRad(lon2 - lon1); var a = Math.pow(Math.sin(dLat / 2),2) + Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.pow(Math.sin(dLon / 2), 2); var c = 2 * Math.asin(Math.sqrt(a)); return R * c; }
Tests:
Distance1
test(distance1)
Distance2
test(distance2)
Distance3
test(distance3)
Distance4
test(distance4)
Distance5
test(distance5)
Distance6
test(getDistance)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
Distance1
Distance2
Distance3
Distance4
Distance5
Distance6
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):
I'll analyze the provided code and benchmark results. **Code Analysis** The provided code appears to be a JavaScript function `distance5` that calculates the distance between two points on the Earth's surface using the Haversine formula. The function takes four parameters: `lat1`, `lon1`, `lat2`, and `lon2`, which represent the latitude and longitude of the two points. The code uses a constant value `R = 6371009` to represent the radius of the Earth in meters, and then applies the Haversine formula to calculate the distance between the two points. The result is returned as a decimal value representing the distance in meters. **Benchmark Results** The provided benchmark results are an array of objects, each representing a single test run. Each object contains various metrics, including: * `RawUAString`: The raw user agent string for the test. * `Browser`: The browser version used for the test. * `DevicePlatform`: The device platform (e.g., Desktop) used for the test. * `OperatingSystem`: The operating system used for the test. * `ExecutionsPerSecond`: The average number of executions per second performed during the test. The results are sorted in descending order by `ExecutionsPerSecond`, with the highest value indicating the fastest execution time. There are six tests, labeled as `Distance6`, `Distance4`, `Distance3`, `Distance5`, `Distance1`, and `Distance2`. **Insights** Based on the provided code and benchmark results, I can infer that: * The `distance5` function is a relatively simple implementation of the Haversine formula. * The test runs are performed using Chrome 69 on a Macintosh device with an Intel processor and macOS 10.13.6 operating system. * The fastest execution time for each test is approximately: + `Distance6`: 148 executions per second + `Distance4`: 134 executions per second + `Distance3`: 123 executions per second + `Distance5`: 119 executions per second + `Distance1`: 113 executions per second + `Distance2`: 114 executions per second These results suggest that the implementation of the Haversine formula in the `distance5` function is relatively efficient, but there may be room for improvement to further optimize performance. Let me know if you'd like me to provide any specific recommendations or insights!
Related benchmarks:
Haversine
Geo distance
Testando
Haversine performance
Comments
Confirm delete:
Do you really want to delete benchmark?