Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Testando
(version: 0)
Comparing performance of:
1 vs 2 vs 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 } function getRandomPoints(n) { return new Array(n).map(() => { const point1 = { latitude: getRandomLat(), longitude: getRandomLon() } const point2 = { latitude: getRandomLat(), longitude: getRandomLon() } }) } var points = getRandomPoints(100)
Tests:
1
points.forEach(() => Haversine(p1, p2))
2
points.forEach(() => Haversine2(p1, p2))
3
points.forEach(() => Haversine3(p1, p2))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
1
2
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):
I'll break down the provided benchmark and explain what's being tested, compared, and their pros/cons. **Benchmark Definition** The benchmark defines three different functions to calculate the distance between two points on Earth using the Haversine formula: `Haversine`, `Haversine2`, and `Haversine3`. **Function Comparison** 1. **`Haversine`**: This function uses the original Haversine formula with a constant radius (`r = 6373`) and converts angles from degrees to radians using the `toRadians` function. * Pros: Simple, easy to understand, and widely accepted formula. * Cons: May be less efficient due to the fixed radius and angle conversion. 2. **`Haversine2`**: This function uses a simplified version of the Haversine formula with a constant radius (`R = 6373`) and calculates the distance using `atan2`. * Pros: Similar to the original formula, but potentially more efficient due to reduced trigonometric operations. * Cons: May be less accurate or stable for certain input values. 3. **`Haversine3`**: This function uses a different approach with a constant radius (`R = 6373`) and calculates the distance using `asin`. * Pros: Could be more efficient due to reduced trigonometric operations, but may be less accurate or stable. * Cons: Less intuitive and potentially harder to understand than the original formula. **Other Considerations** * The benchmark uses a random generation of points (`getRandomLat` and `getRandomLon`) to create a large dataset for testing. This allows for more realistic and varied input values. * The test cases use `forEach` to iterate over the generated points and call each function, which provides a representative workload for the functions being tested. **Library/ Framework** The benchmark uses the built-in JavaScript `Math` library, specifically its constants (`PI`, `sqrt`, `cos`, etc.) and functions (e.g., `toRadians`, `atan2`). No external libraries or frameworks are required. **Special JS Feature/Syntax** There is no specific use of advanced JavaScript features or syntax in this benchmark. The code focuses on testing the performance of simple mathematical functions. **Alternatives** Other alternatives for calculating distances between two points on Earth include: * Using a more accurate formula, such as the Vincenty formula. * Utilizing pre-computed values or lookups for common angles and radii. * Employing parallel processing or multithreading to accelerate distance calculations. * Leveraging specialized libraries or frameworks optimized for geographic computing. Keep in mind that these alternatives may introduce additional complexity or overhead, which could impact performance. The benchmark's simplicity and focus on comparing the three different functions make it an excellent starting point for evaluating their relative efficiency.
Related benchmarks:
Haversine
Haversine
trigata
Haversine performance
Comments
Confirm delete:
Do you really want to delete benchmark?