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 = 6367000; //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.0090.00616.88
8.3.50.0130.00622.12
8.3.40.0070.01119.11
8.3.30.0120.00319.17
8.3.20.0150.00019.10
8.3.10.0040.00422.36
8.3.00.0080.00022.35
8.2.180.0040.01517.25
8.2.170.0120.00322.96
8.2.160.0120.00422.67
8.2.150.0130.00724.18
8.2.140.0090.00624.66
8.2.130.0110.00420.33
8.2.120.0050.00226.35
8.2.110.0070.00320.89
8.2.100.0030.01018.24
8.2.90.0050.00319.86
8.2.80.0000.00818.30
8.2.70.0080.00018.00
8.2.60.0000.00918.30
8.2.50.0060.00618.10
8.2.40.0040.00420.96
8.2.30.0030.00521.39
8.2.20.0030.00518.57
8.2.10.0080.00018.81
8.2.00.0040.00418.09
8.1.280.0070.00725.92
8.1.270.0110.00424.29
8.1.260.0000.00828.09
8.1.250.0040.00428.09
8.1.240.0060.00321.31
8.1.230.0040.00719.48
8.1.220.0000.00818.14
8.1.210.0030.00518.77
8.1.200.0060.00317.85
8.1.190.0000.00817.72
8.1.180.0030.00618.10
8.1.170.0000.00819.46
8.1.160.0030.00522.54
8.1.150.0070.00320.96
8.1.140.0040.00420.25
8.1.130.0000.00718.12
8.1.120.0040.00417.94
8.1.110.0000.00717.90
8.1.100.0050.00317.95
8.1.90.0040.00417.93
8.1.80.0040.00417.84
8.1.70.0000.00817.84
8.1.60.0050.00318.12
8.1.50.0040.00418.01
8.1.40.0050.00318.02
8.1.30.0030.00518.00
8.1.20.0030.00618.09
8.1.10.0030.00518.06
8.1.00.0090.00017.97
8.0.300.0040.00418.77
8.0.290.0080.00017.25
8.0.280.0070.00018.92
8.0.270.0040.00417.67
8.0.260.0030.00317.82
8.0.250.0000.00717.39
8.0.240.0050.00217.34
8.0.230.0040.00417.41
8.0.220.0070.00017.38
8.0.210.0080.00017.34
8.0.200.0070.00017.55
8.0.190.0080.00017.41
8.0.180.0090.00317.44
8.0.170.0060.00317.38
8.0.160.0040.00417.29
8.0.150.0000.00717.36
8.0.140.0040.00417.20
8.0.130.0000.00713.81
8.0.120.0000.00817.32
8.0.110.0040.00417.39
8.0.100.0050.00317.21
8.0.90.0000.00717.44
8.0.80.0120.00617.24
8.0.70.0000.00717.32
8.0.60.0040.00417.41
8.0.50.0040.00417.21
8.0.30.0110.00617.56
8.0.20.0100.00917.50
8.0.10.0050.00317.35
8.0.00.0150.00417.11
7.4.330.0020.00215.55
7.4.320.0030.00317.01
7.4.300.0070.00017.14
7.4.290.0020.00517.01
7.4.280.0030.00517.07
7.4.270.0000.00716.99
7.4.260.0050.00317.02
7.4.250.0000.00716.91
7.4.240.0080.00017.10
7.4.230.0070.00016.90
7.4.220.0070.01017.00
7.4.210.0090.00916.81
7.4.200.0040.00417.17
7.4.160.0090.01116.75
7.4.150.0090.00917.40
7.4.140.0060.01317.86
7.4.130.0080.01116.89
7.4.120.0090.00916.99
7.4.110.0080.01216.76
7.4.100.0100.01416.88
7.4.90.0170.01016.84
7.4.80.0090.00919.39
7.4.70.0140.00316.77
7.4.60.0100.00716.74
7.4.50.0040.00717.20
7.4.40.0130.00316.55
7.4.30.0090.01516.95
7.4.00.0060.01115.27
7.3.330.0030.00313.92
7.3.320.0070.00013.86
7.3.310.0040.00416.73
7.3.300.0050.00316.94
7.3.290.0000.00716.70
7.3.280.0060.01116.68
7.3.270.0090.00917.40
7.3.260.0130.00616.75
7.3.250.0090.01216.75
7.3.240.0060.01116.71
7.3.230.0130.00416.96
7.3.210.0030.01516.66
7.3.200.0090.00916.71
7.3.190.0130.01016.87
7.3.180.0060.01016.89
7.3.170.0060.01716.55
7.3.160.0070.01616.82
7.3.120.0060.01115.08
7.3.110.0060.01215.20
7.3.100.0130.00715.18
7.3.90.0030.01315.22
7.3.80.0090.00915.09
7.3.70.0070.01015.10
7.3.60.0070.01015.44
7.3.50.0130.00315.32
7.3.40.0090.00315.25
7.3.30.0090.00314.93
7.3.20.0070.01117.10
7.3.10.0060.01016.71
7.3.00.0030.00916.78
7.2.330.0060.01217.00
7.2.320.0090.01617.15
7.2.310.0070.01117.05
7.2.300.0160.00716.88
7.2.290.0140.00916.95
7.2.250.0030.01415.73
7.2.240.0070.01315.32
7.2.230.0090.00915.42
7.2.220.0070.01115.52
7.2.210.0040.01115.46
7.2.200.0070.01015.59
7.2.190.0030.00715.10
7.2.180.0120.00415.65
7.2.170.0090.00615.53
7.2.60.0070.00717.37
7.2.50.0040.00917.26
7.2.00.0030.01319.80
7.1.330.0120.00316.23
7.1.320.0100.00716.00
7.1.310.0060.00916.06
7.1.300.0090.00616.10
7.1.290.0070.00715.86
7.1.280.0000.00916.06
7.1.270.0100.00716.32
7.1.260.0100.00615.89
7.1.200.0040.00816.12
7.1.70.0040.00717.72
7.1.60.0060.00617.63
7.1.00.0070.07722.79
7.0.200.0160.00715.33
7.0.120.0100.06722.41
7.0.110.0100.06322.26
7.0.100.0270.04722.26
7.0.90.0170.06022.41
7.0.80.0070.06022.40
7.0.70.0500.05020.61
7.0.60.0230.05020.55
7.0.50.0000.06722.30
7.0.40.0070.06022.25
7.0.30.0130.07320.49
7.0.20.0170.07322.29
7.0.10.0130.06020.64
7.0.00.0130.05722.27
5.6.270.0130.07721.38
5.6.260.0170.06321.38
5.6.250.0170.05721.11
5.6.240.0430.05721.34
5.6.230.0230.06021.36
5.6.220.0130.05321.09
5.6.210.0130.05721.22
5.6.200.0100.05721.16
5.6.190.0130.06321.00
5.6.180.0270.05721.25
5.6.170.0200.05721.33
5.6.160.0230.07021.39
5.6.150.0170.07321.07
5.6.140.0100.06021.29
5.6.130.0070.05721.29
5.6.120.0030.06321.10
5.6.110.0030.08321.32
5.6.100.0370.08021.17
5.6.90.0100.07721.21
5.6.80.0070.06720.71
5.6.70.0200.06720.72
5.6.60.0230.05320.63
5.6.50.0100.07020.78
5.6.40.0170.05320.38
5.6.30.0130.06020.43
5.6.20.0200.05020.54
5.6.10.0100.06020.35
5.6.00.0200.06320.66

preferences:
61.77 ms | 401 KiB | 5 Q