3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** *求两个已知经纬度之间的距离,单位为米 *@param lng1,lng2 经度 *@param lat1,lat2 纬度 *@return float 距离,单位米 *@author www.phpernote.com **/ function getdistance($lng1,$lat1,$lng2,$lat2){ //将角度转为狐度 $radLat1=deg2rad($lat1);//deg2rad()函数将角度转换为弧度 $radLat2=deg2rad($lat2); $radLng1=deg2rad($lng1); $radLng2=deg2rad($lng2); $a=$radLat1-$radLat2; $b=$radLng1-$radLng2; $s=2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))*6378.137*1000; return $s; } echo getdistance(31.2014966,121.40233369999998,31.22323799999999,121.44552099999998); function calculateSignDistance($longitude1, $latitude1, $longitude2, $latitude2) { $lat1 = ($latitude1 * pi() ) / 180; $lng1 = ($longitude1 * pi() ) / 180; $lat2 = ($longitude2 * pi() ) / 180; $lng2 = ($latitude2 * pi() ) / 180; $calcLongitude = $lng2 - $lng1; $calcLatitude = $lat2 - $lat1; $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2); $stepTwo = 2 * asin(sqrt($stepOne)); return 6378.137*1000 * $stepTwo; } echo "\n"; echo calculateSignDistance(31.2014966,121.40233369999998,31.22323799999999,121.44552099999998); /** *求两个已知经纬度之间的距离,单位为千米 *@param lng1,lng2 经度 *@param lat1,lat2 纬度 *@return float 距离,单位千米 **/ function distance($lng1,$lat1,$lng2,$lat2)//根据经纬度计算距离 { //将角度转为弧度 $radLat1=deg2rad($lat1); $radLat2=deg2rad($lat2); $radLng1=deg2rad($lng1); $radLng2=deg2rad($lng2); $a=$radLat1-$radLat2;//两纬度之差,纬度<90 $b=$radLng1-$radLng2;//两经度之差纬度<180 $s=2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))*6378.137*1000; return $s; } echo "\n"; echo distance(31.2014966,121.40233369999998,31.22323799999999,121.44552099999998); function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) { $theta = $longitude1 - $longitude2; $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta))); $miles = acos($miles); $miles = rad2deg($miles); $miles = $miles * 60 * 1.1515; $feet = $miles * 5280; $yards = $feet / 3; $kilometers = $miles * 1.609344; $meters = $kilometers * 1000; return compact('miles','feet','yards','kilometers','meters'); } $point1 = array('lat' => 31.2014966,121, 'long' => 121.40233369999998); $point2 = array('lat' => 31.22323799999999, 'long' => 121.44552099999998); $distance = getDistanceBetweenPointsNew($point1['lat'], $point1['long'], $point2['lat'], $point2['long']); foreach ($distance as $unit => $value) { echo $unit.': '.number_format($value,4).'<br />'; } /** * @desc 根据两点间的经纬度计算距离 * @param float $lat 纬度值 * @param float $lng 经度值 */ function getDistance3($lat1, $lng1, $lat2, $lng2) { $earthRadius = 6378137; //approximate radius of earth in meters /* Convert these degrees to radians to work with the formula */ $lat1 = ($lat1 * pi() ) / 180; $lng1 = ($lng1 * pi() ) / 180; $lat2 = ($lat2 * pi() ) / 180; $lng2 = ($lng2 * pi() ) / 180; /* Using the Haversine formula http://en.wikipedia.org/wiki/Haversine_formula calculate the distance */ $calcLongitude = $lng2 - $lng1; $calcLatitude = $lat2 - $lat1; $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2); $stepTwo = 2 * asin(min(1, sqrt($stepOne))); $calculatedDistance = $earthRadius * $stepTwo; return round($calculatedDistance); } echo "\n"; echo getDistance3(31.2014966,121.40233369999998,31.22323799999999,121.44552099999998);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0070.01117.13
8.3.50.0200.00018.57
8.3.40.0090.00619.29
8.3.30.0090.00619.29
8.3.20.0040.01119.00
8.3.10.0040.00422.55
8.3.00.0040.00422.58
8.2.180.0140.00417.38
8.2.170.0040.01122.96
8.2.160.0070.00722.46
8.2.150.0120.00324.18
8.2.140.0040.01124.66
8.2.130.0040.00426.16
8.2.120.0050.00321.62
8.2.110.0030.00621.17
8.2.100.0030.00918.40
8.2.90.0030.00619.92
8.2.80.0080.00018.40
8.2.70.0000.00818.13
8.2.60.0040.00418.66
8.2.50.0030.00618.13
8.2.40.0040.00421.05
8.2.30.0080.00019.82
8.2.20.0000.00818.52
8.2.10.0000.00718.53
8.2.00.0060.00318.23
8.1.280.0150.00325.92
8.1.270.0080.00024.25
8.1.260.0050.00326.35
8.1.250.0000.00928.09
8.1.240.0060.00324.30
8.1.230.0000.01119.58
8.1.220.0030.00518.16
8.1.210.0080.00018.77
8.1.200.0070.00317.86
8.1.190.0040.00418.26
8.1.180.0030.00618.10
8.1.170.0050.00319.47
8.1.160.0020.00522.61
8.1.150.0030.00621.12
8.1.140.0060.00320.00
8.1.130.0000.00718.04
8.1.120.0000.00717.86
8.1.110.0040.00417.96
8.1.100.0030.00617.82
8.1.90.0080.00017.85
8.1.80.0050.00317.94
8.1.70.0000.00817.85
8.1.60.0000.00817.98
8.1.50.0030.00517.98
8.1.40.0000.00818.11
8.1.30.0030.00518.15
8.1.20.0060.00318.20
8.1.10.0040.00418.02
8.1.00.0030.00517.89
8.0.300.0040.00418.77
8.0.290.0060.00317.25
8.0.280.0040.00418.96
8.0.270.0000.00717.89
8.0.260.0060.00017.77
8.0.250.0000.00717.43
8.0.240.0040.00417.32
8.0.230.0000.00717.42
8.0.220.0000.00717.31
8.0.210.0030.00317.34
8.0.200.0000.00717.45
8.0.190.0090.00017.47
8.0.180.0100.00017.30
8.0.170.0000.00817.36
8.0.160.0040.00417.37
8.0.150.0040.00417.22
8.0.140.0000.00817.23
8.0.130.0060.00013.82
8.0.120.0040.00417.23
8.0.110.0070.00017.41
8.0.100.0040.00417.45
8.0.90.0040.00417.54
8.0.80.0030.01317.16
8.0.70.0000.00817.26
8.0.60.0050.00217.43
8.0.50.0070.00017.45
8.0.30.0110.00617.40
8.0.20.0080.01417.49
8.0.10.0050.00217.48
8.0.00.0130.01016.99
7.4.330.0050.00015.55
7.4.320.0060.00016.88
7.4.300.0000.00616.98
7.4.290.0080.00017.09
7.4.280.0040.00417.05
7.4.270.0030.00316.95
7.4.260.0070.00016.84
7.4.250.0090.00016.97
7.4.240.0040.00417.06
7.4.230.0000.00717.26
7.4.220.0070.01016.86
7.4.210.0080.00816.85
7.4.200.0030.00316.82
7.4.160.0090.00816.79
7.4.150.0110.00817.40
7.4.140.0110.00717.86
7.4.130.0090.00816.88
7.4.120.0120.00716.90
7.4.110.0120.00616.69
7.4.100.0140.00716.76
7.4.90.0060.01216.78
7.4.80.0140.00419.39
7.4.70.0070.01017.11
7.4.60.0080.00816.67
7.4.50.0000.01816.85
7.4.40.0150.00316.76
7.4.30.0120.01216.71
7.4.10.0030.01616.10
7.4.00.0090.00815.91
7.3.330.0030.00313.92
7.3.320.0030.00313.70
7.3.310.0000.00716.90
7.3.300.0000.00716.82
7.3.290.0030.00316.84
7.3.280.0100.00916.69
7.3.270.0160.00317.40
7.3.260.0120.00716.77
7.3.250.0100.00716.76
7.3.240.0120.01016.73
7.3.230.0170.00016.97
7.3.210.0090.00916.59
7.3.200.0120.00616.77
7.3.190.0150.00616.63
7.3.180.0100.00716.95
7.3.170.0130.00616.78
7.3.160.0120.01216.79
7.3.130.0090.00816.00
7.3.120.0020.01715.88
7.3.110.0110.00816.19
7.3.100.0090.00916.19
7.3.90.0100.00816.17
7.3.80.0080.00516.04
7.3.70.0090.00515.89
7.3.60.0110.00615.92
7.3.50.0080.00616.04
7.3.40.0080.01016.09
7.3.30.0070.01415.90
7.3.20.0050.01217.65
7.3.10.0040.01017.83
7.3.00.0050.00718.01
7.2.330.0140.00317.15
7.2.320.0040.01517.09
7.2.310.0120.00617.25
7.2.300.0030.02117.15
7.2.290.0060.01217.07
7.2.260.0120.00516.24
7.2.250.0070.01016.32
7.2.240.0050.01216.24
7.2.230.0080.01216.37
7.2.220.0090.01116.22
7.2.210.0050.01216.18
7.2.200.0030.00816.30
7.2.190.0070.00516.14
7.2.180.0020.01416.02
7.2.170.0030.01516.34
7.2.160.0080.01116.07
7.2.150.0050.01418.08
7.2.140.0070.00918.22
7.2.130.0050.01018.25
7.2.120.0070.01018.00
7.2.110.0080.00718.11
7.2.100.0060.00718.08
7.2.90.0070.00917.96
7.2.80.0060.01017.80
7.2.70.0080.00917.99
7.2.60.0040.01117.71
7.2.50.0070.01018.15
7.2.40.0050.00917.99
7.2.30.0080.00718.13
7.2.20.0080.00818.04
7.2.10.0070.00818.06
7.2.00.0010.01418.36
7.1.330.0040.00916.92
7.1.320.0100.00816.98
7.1.310.0060.00617.07
7.1.300.0070.00817.03
7.1.290.0050.00816.87
7.1.280.0070.01116.96
7.1.270.0020.01717.01
7.1.260.0100.00717.10
7.1.250.0070.00716.91
7.1.240.0100.00516.99
7.1.230.0050.00916.78
7.1.220.0070.00717.07
7.1.210.0020.01317.09
7.1.200.0030.01016.68
7.1.190.0070.00416.85
7.1.180.0050.00616.85
7.1.170.0050.01116.99
7.1.160.0090.00716.81
7.1.150.0070.00616.94
7.1.140.0030.00816.87
7.1.130.0030.01017.03
7.1.120.0040.01117.00
7.1.110.0030.00716.88
7.1.100.0050.00817.38
7.1.90.0070.00816.77
7.1.80.0000.01116.89
7.1.70.0040.00816.98
7.1.60.0040.01017.15
7.1.50.0080.00816.94
7.1.40.0050.01116.86
7.1.30.0030.00917.03
7.1.20.0030.00716.97
7.1.10.0030.00817.14
7.1.00.0070.03218.96
7.0.330.0040.00916.64
7.0.320.0070.00716.57
7.0.310.0110.00316.73
7.0.300.0070.00516.50
7.0.290.0020.01016.54
7.0.280.0080.00716.66
7.0.270.0050.00716.64
7.0.260.0020.01216.57
7.0.250.0020.01016.64
7.0.240.0070.00516.54
7.0.230.0120.00316.79
7.0.220.0030.00816.59
7.0.210.0040.00816.54
7.0.200.0090.00716.13
7.0.190.0090.00716.53
7.0.180.0080.00716.52
7.0.170.0070.00616.61
7.0.160.0020.01016.59
7.0.150.0040.00816.72
7.0.140.0080.00516.72
7.0.130.0070.00816.65
7.0.120.0060.02418.58
7.0.110.0110.02318.46
7.0.100.0110.02418.51
7.0.90.0100.02918.49
7.0.80.0050.03518.56
7.0.70.0100.03418.03
7.0.60.0120.02217.90
7.0.50.0110.02518.53
7.0.40.0080.02517.21
7.0.30.0100.02817.21
7.0.20.0080.03116.61
7.0.10.0140.01717.16
7.0.00.0140.02217.18
5.6.400.0030.01415.76
5.6.390.0050.01015.43
5.6.380.0060.00615.58
5.6.370.0040.01015.39
5.6.360.0050.00815.49
5.6.350.0040.00715.44
5.6.340.0030.01015.49
5.6.330.0060.00815.42
5.6.320.0070.00815.84
5.6.310.0050.00815.64
5.6.300.0030.01015.53
5.6.290.0030.01215.71
5.6.280.0080.01215.63
5.6.270.0100.02517.43
5.6.260.0070.02917.36
5.6.250.0060.02817.60
5.6.240.0100.02517.41
5.6.230.0090.02717.46
5.6.220.0140.02117.38
5.6.210.0130.02317.52
5.6.200.0090.02817.46
5.6.190.0080.02817.49
5.6.180.0100.02717.39
5.6.170.0140.02717.34
5.6.160.0090.02517.45
5.6.150.0070.02717.49
5.6.140.0110.03017.44
5.6.130.0100.02917.54
5.6.120.0110.02517.42
5.6.110.0060.03017.39
5.6.100.0090.03217.57
5.6.90.0150.02617.24
5.6.80.0070.02517.23
5.6.70.0080.02717.20
5.6.60.0070.03117.21
5.6.50.0110.02617.29
5.6.40.0110.02517.15
5.6.30.0120.02517.17
5.6.20.0110.03117.04
5.6.10.0090.02617.17
5.6.00.0120.03517.20

preferences:
58.27 ms | 400 KiB | 5 Q