geolocation

Benchmark created by Lukas on


Setup

var geodistance1 = function(A, B) {
    
        var A = A || [55.949444, -3.160278],
            B = B || [51.507222, -0.1275];
    
        return 3956 * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin((A[0] - Math.abs(B[0])) * Math.PI / 180 / 2), 2) + Math.cos(A[0] * Math.PI / 180) * Math.cos(Math.abs(B[0]) * Math.PI / 180) * Math.pow(Math.sin((A[1] - B[1]) * Math.PI / 180 / 2), 2)));
    
    };
    
    var geodistance2 = function(A, B) {
    
        var A = A || [55.949444, -3.160278],
            B = B || [51.507222, -0.1275],
            ASIN = Math.asin,
            SQRT = Math.sqrt,
            POW = Math.pow,
            SIN = Math.sin,
            ABS = Math.abs,
            PI = Math.PI,
            COS = Math.cos;
    
        return 3956 * 2 * ASIN(SQRT(POW(SIN((A[0] - ABS(B[0])) * PI / 180 / 2), 2) + COS(A[0] * PI / 180) * COS(ABS(B[0]) * PI / 180) * POW(SIN((A[1] - B[1]) * PI / 180 / 2), 2)));
    
    };
    
    var geodistance3 = function(A, B) {
    
        var A = A || [55.949444, -3.160278],
            B = B || [51.507222, -0.1275],
    M = Math,
            ASIN = M.asin,
            SQRT = M.sqrt,
            POW = M.pow,
            SIN = M.sin,
            ABS = M.abs,
            PI = M.PI,
            COS = M.cos;
    
        return 3956 * 2 * ASIN(SQRT(POW(SIN((A[0] - ABS(B[0])) * PI / 180 / 2), 2) + COS(A[0] * PI / 180) * COS(ABS(B[0]) * PI / 180) * POW(SIN((A[1] - B[1]) * PI / 180 / 2), 2)));
    
    };

Test runner

Ready to run.

Testing in
TestOps/sec
vars not cached
geodistance1();
ready
vars cached
geodistance2();
ready
math cached
geodistance3();
ready

Revisions

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

  • Revision 1: published by Lukas on