Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Haversine performance
(version: 0)
Comparing performance of:
Haversine 1 vs Haversine 2 vs Haversine 3
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const { PI, sqrt, cos, sin, asin, pow, atan2, random } = Math function toRadians(angle) { return PI * angle / 180 } function Haversine(point1, point2) { const r = 6373 const latOrigem = toRadians(point1.latitude) const lonOrigem = toRadians(point1.longitude) const latDistino = toRadians(point2.latitude) const lonDistino = toRadians(point2.longitude) const a = pow( sin((latDistino - latOrigem) / 2), 2) + cos(latOrigem) * cos(latDistino) * pow(sin((lonDistino - lonOrigem) / 2), 2) const c = 2 * atan2(sqrt(a), sqrt(1 - a)) return c * r } function Haversine2(point1, point2) { const R = 6373 const dLat = toRadians(point2.latitude - point1.latitude) const dLon = toRadians(point2.longitude - point1.longitude) const ht = 0.5 - cos(dLat) / 2 + cos(toRadians(point1.latitude)) * cos(toRadians(point2.latitude)) * (1 - cos(dLon)) / 2 return R * 2 * asin(sqrt(ht)) } function Haversine3(point1, point2) { const R = 6373 const ph1 = toRadians(point1.longitude - point2.longitude) const th1 = toRadians(point1.latitude) const th2 = toRadians(point2.latitude) const cth1 = cos(th1) const dz = sin(th1) - sin(th2) const dx = cos(ph1) * cth1 - cos(th2) const dy = sin(ph1) * cth1 return 2 * R * asin(sqrt(dx * dx + dy * dy + dz * dz) / 2) } function getRandomLat() { return random() * (90 + 90 + 1) - 90 } function getRandomLon() { return Math.random() * (180 + 180 + 1) - 180 } var p1 = { latitude: getRandomLat(), longitude: getRandomLon() } var p2 = { latitude: getRandomLat(), longitude: getRandomLon() }
Tests:
Haversine 1
Haversine(p1,p2)
Haversine 2
Haversine2(p1,p2)
Haversine 3
Haversine3(p1,p2)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Haversine 1
Haversine 2
Haversine 3
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):
**Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided JSON represents the benchmark definition, which tests three different implementations of the Haversine formula for calculating distances between two points on a sphere (in this case, the Earth). **Benchmark Definition** The benchmark definition consists of a JavaScript function (`Haversine`) that calculates the distance between two points using the Haversine formula. The formula is implemented in three different ways: `Haversine1`, `Haversine2`, and `Haversine3`. **Options Compared** The benchmark compares the performance of the three implementations: * `Haversine1`: This implementation uses a more traditional approach, with multiple calculations involving trigonometric functions. * `Haversine2`: This implementation uses a simplified version of the formula, which is faster but less accurate. * `Haversine3`: This implementation uses an alternative approach that involves spherical coordinates and trigonometric identities. **Pros and Cons** Here's a brief overview of the pros and cons of each implementation: * `Haversine1`: + Pros: More accurate, easier to understand. + Cons: Slower performance due to multiple calculations. * `Haversine2`: + Pros: Faster performance, simpler code. + Cons: Less accurate, may not be suitable for critical applications. * `Haversine3`: + Pros: Fastest performance, most optimized code. + Cons: Most complex implementation, harder to understand. **Library and Purpose** The `Math` library is used throughout the benchmark definition. The `Math` library provides mathematical functions such as `sin`, `cos`, `tan`, and others, which are used in the Haversine formula implementations. **Special JS Feature or Syntax** None of the implementations use any special JavaScript features or syntax beyond basic arithmetic operations and function calls. **Other Considerations** When designing a benchmark like this, it's essential to consider factors such as: * Input data: The choice of random latitude and longitude values can affect the performance results. * Hardware platform: The benchmark is executed on a desktop computer with Chrome 103. Other platforms or browsers may produce different results. **Alternative Implementations** Other implementations of the Haversine formula exist, which might be worth considering in a real-world scenario: * Using a dedicated library or framework for geolocation calculations (e.g., OpenLocationCode). * Implementing the formula using a more efficient algorithm, such as the "spherical law of cosines" method. * Optimizing the code for specific use cases, such as high-performance computing or mobile devices. These alternatives might not be suitable for all applications, but they could provide better performance or accuracy in certain situations.
Related benchmarks:
Haversine Distance tests
Geo distance
Geo distance 2
Testando
Comments
Confirm delete:
Do you really want to delete benchmark?