hodacvu (v12)

Revision 12 of this benchmark created by Vu.Ho on


Description

test distance

Setup

function deg2rad(deg) {
      return deg * Math.PI / 180
    }

Test runner

Ready to run.

Testing in
TestOps/sec
1
function distance(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;
}

distance(16.0770787, 108.21848090000003, 16.0751817, 108.2219892);
ready
2
 
ready
3
 
ready
4
 
ready
5
 
ready
6
 
ready
7
 
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.