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); /** * @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 = deg2rad($lat1); $lng1 = deg2rad($lng1); $lat2 = deg2rad($lat2); $lng2 = deg2rad($lng2); /* Using the Haversine formula http://en.wikipedia.org/wiki/Haversine_formula calculate the distance */ $calcLongitude = $lng1-$lng2 ; $calcLatitude = $lat1-$lat2 ; $calculatedDistance = 2 * asin(sqrt(pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2))) *6378.137*1000 ; return $calculatedDistance; } echo "\n"; echo getDistance3(121.40233369999998,31.2014966,121.44552099999998,31.22323799999999);

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.5.10.0090.00820.51
8.5.00.0120.00921.95
8.4.160.0130.00923.98
8.4.150.0020.00014.05
8.4.140.0140.00617.97
8.4.130.0120.00819.11
8.4.120.0100.00624.56
8.4.110.0130.00719.14
8.4.100.0110.00619.32
8.4.90.0090.01022.66
8.4.80.0040.00419.05
8.4.70.0090.01119.13
8.4.60.0100.00919.48
8.4.50.0050.00420.79
8.4.40.0130.00619.77
8.4.30.0160.00320.17
8.4.20.0080.00018.00
8.4.10.0090.00019.79
8.3.280.0110.01018.74
8.3.270.0080.01117.09
8.3.260.0140.00717.05
8.3.250.0130.00619.33
8.3.240.0090.00717.44
8.3.230.0160.00417.07
8.3.220.0100.00619.34
8.3.210.0110.00718.79
8.3.200.0050.00417.25
8.3.190.0100.00917.71
8.3.180.0100.00919.49
8.3.170.0030.00617.00
8.3.160.0120.00617.62
8.3.150.0070.01017.23
8.3.140.0110.00719.28
8.3.130.0050.00516.92
8.3.120.0140.00519.49
8.3.110.0030.00620.94
8.3.100.0060.00317.04
8.3.90.0040.00416.88
8.3.80.0030.00617.97
8.3.70.0000.01518.89
8.3.60.0090.00917.00
8.3.50.0100.01222.14
8.3.40.0060.00919.21
8.3.30.0150.00419.35
8.3.20.0060.00319.14
8.3.10.0080.00022.54
8.3.00.0040.00422.19
8.2.290.0060.00221.07
8.2.280.0160.00419.22
8.2.270.0040.00417.40
8.2.260.0110.00717.18
8.2.250.0000.00916.75
8.2.240.0180.00018.91
8.2.230.0060.00322.58
8.2.220.0000.00824.06
8.2.210.0050.00326.77
8.2.200.0030.00618.43
8.2.190.0060.00916.75
8.2.180.0150.00317.25
8.2.170.0110.00422.96
8.2.160.0030.01022.68
8.2.150.0060.00324.18
8.2.140.0080.00024.66
8.2.130.0000.00720.33
8.2.120.0080.00026.35
8.2.110.0120.00019.43
8.2.100.0090.00318.41
8.2.90.0040.00419.57
8.2.80.0030.00518.13
8.2.70.0040.00418.00
8.2.60.0000.00818.30
8.2.50.0040.00418.10
8.2.40.0080.00020.98
8.2.30.0080.00021.37
8.2.20.0000.00718.37
8.2.10.0080.00018.58
8.2.00.0000.00718.11
8.1.330.0100.00922.25
8.1.320.0110.00816.55
8.1.310.0110.00716.29
8.1.300.0090.00916.50
8.1.290.0060.00318.88
8.1.280.0140.00725.92
8.1.270.0040.00424.20
8.1.260.0070.00028.09
8.1.250.0040.00428.09
8.1.240.0090.00024.50
8.1.230.0110.00417.82
8.1.220.0040.00418.16
8.1.210.0080.00018.77
8.1.200.0070.00317.60
8.1.190.0000.00819.39
8.1.180.0000.00818.10
8.1.170.0060.00319.40
8.1.160.0040.00422.67
8.1.150.0060.00319.19
8.1.140.0040.00420.00
8.1.130.0070.00018.25
8.1.120.0040.00417.88
8.1.110.0000.00817.97
8.1.100.0000.00717.74
8.1.90.0080.00017.82
8.1.80.0000.00717.83
8.1.70.0000.00817.78
8.1.60.0030.00618.02
8.1.50.0040.00418.02
8.1.40.0040.00417.96
8.1.30.0050.00318.06
8.1.20.0090.00018.05
8.1.10.0080.00017.86
8.1.00.0030.00517.88
8.0.300.0040.00418.77
8.0.290.0000.00817.25
8.0.280.0070.00018.98
8.0.270.0030.00317.77
8.0.260.0030.00317.75
8.0.250.0000.00717.39
8.0.240.0000.00817.41
8.0.230.0070.00017.40
8.0.220.0080.00017.36
8.0.210.0030.00317.36
8.0.200.0060.00017.38
8.0.190.0000.00917.27
8.0.180.0030.00717.30
8.0.170.0050.00317.29
8.0.160.0000.00717.32
8.0.150.0030.00317.27
8.0.140.0040.00417.33
8.0.130.0050.00013.76
8.0.120.0080.00017.25
8.0.110.0040.00417.34
8.0.100.0070.00017.33
8.0.90.0000.00817.21
8.0.80.0100.00617.06
8.0.70.0000.00817.27
8.0.60.0070.00017.18
8.0.50.0080.00017.15
8.0.30.0060.01417.38
8.0.20.0090.01317.45
8.0.10.0080.00017.19
8.0.00.0120.00616.86
7.4.330.0020.00215.65
7.4.320.0030.00316.91
7.4.300.0030.00316.89
7.4.290.0040.00417.11
7.4.280.0040.00416.84
7.4.270.0030.00316.96
7.4.260.0030.00316.91
7.4.250.0020.00517.01
7.4.240.0000.00816.83
7.4.230.0030.00316.74
7.4.220.0170.00316.93
7.4.210.0040.01416.88
7.4.200.0000.00716.86
7.4.160.0090.00816.79
7.4.150.0110.00717.40
7.4.140.0120.00517.86
7.4.130.0120.00516.83
7.4.120.0080.00916.71
7.4.110.0080.00816.83
7.4.100.0090.00916.82
7.4.90.0090.00916.79
7.4.80.0080.00819.39
7.4.70.0040.01316.73
7.4.60.0160.00016.71
7.4.50.0090.00316.85
7.4.40.0070.01116.88
7.4.30.0090.01416.66
7.4.00.0060.01115.29
7.3.330.0030.00313.78
7.3.320.0000.00513.58
7.3.310.0000.00716.75
7.3.300.0000.00716.85
7.3.290.0040.00416.69
7.3.280.0110.00616.59
7.3.270.0100.00717.40
7.3.260.0140.00516.82
7.3.250.0070.01016.65
7.3.240.0070.01616.69
7.3.230.0170.00016.71
7.3.210.0140.00416.59
7.3.200.0060.01016.57
7.3.190.0130.00916.47
7.3.180.0130.00716.57
7.3.170.0110.00716.66
7.3.160.0130.00616.70
7.3.120.0050.01315.21
7.3.110.0030.01514.98
7.3.100.0120.00315.18
7.3.90.0070.00715.18
7.3.80.0090.00515.10
7.3.70.0050.00915.24
7.3.60.0040.00915.03
7.3.50.0030.01215.24
7.3.40.0070.00815.05
7.3.30.0020.00915.34
7.3.20.0050.00916.94
7.3.10.0050.01416.91
7.3.00.0090.00616.73
7.2.330.0160.00316.58
7.2.320.0030.01416.95
7.2.310.0160.00916.93
7.2.300.0090.01016.61
7.2.290.0060.01016.99
7.2.250.0110.00615.34
7.2.240.0020.01515.22
7.2.230.0050.01215.19
7.2.220.0070.00515.46
7.2.210.0060.00815.28
7.2.200.0070.00715.33
7.2.190.0090.00615.43
7.2.180.0070.00815.28
7.2.170.0040.01215.19
7.2.130.0200.00016.57
7.2.120.0140.00716.96
7.2.110.0030.01016.84
7.2.100.0150.00416.67
7.2.90.0090.00916.21
7.2.80.0160.00616.44
7.2.70.0070.01716.69
7.2.60.0110.00916.97
7.2.50.0110.01217.02
7.2.40.0150.00316.64
7.2.30.0120.00816.27
7.2.20.0170.00617.21
7.2.10.0160.00016.43
7.2.00.0030.01218.38
7.1.330.0060.00815.82
7.1.320.0040.00616.09
7.1.310.0060.00515.99
7.1.300.0020.00815.97
7.1.290.0080.00815.85
7.1.280.0100.00716.13
7.1.270.0040.00715.95
7.1.260.0090.00315.83
7.1.250.0200.00015.63
7.1.200.0040.01115.99
7.1.70.0000.01017.42
7.1.60.0000.01017.69
7.1.00.0100.07022.79
7.0.200.0150.00615.17
7.0.120.0070.07722.38
7.0.110.0100.05722.36
7.0.100.0230.07022.26
7.0.90.0100.08022.48
7.0.80.0170.07022.27
7.0.70.0130.05322.20
7.0.60.0070.06022.30
7.0.50.0100.07322.27
7.0.40.0170.05322.26
7.0.30.0100.05322.37
7.0.20.0070.05722.47
7.0.10.0030.05722.26
7.0.00.0070.06022.24
5.6.270.0200.07021.27
5.6.260.0230.04721.01
5.6.250.0230.05021.31
5.6.240.0130.07021.18
5.6.230.0100.05721.10
5.6.220.0170.05321.38
5.6.210.0070.06021.37
5.6.200.0000.07721.24
5.6.190.0100.05721.06
5.6.180.0100.05321.29
5.6.170.0100.05321.31
5.6.160.0070.06021.27
5.6.150.0170.06021.09
5.6.140.0070.05721.35
5.6.130.0130.05321.17
5.6.120.0030.06321.09
5.6.110.0130.05321.21
5.6.100.0070.06021.09
5.6.90.0170.04721.25
5.6.80.0100.06720.61
5.6.70.0030.08020.47
5.6.60.0130.05720.71
5.6.50.0100.05020.69
5.6.40.0100.05320.70
5.6.30.0100.05320.43
5.6.20.0100.05720.65
5.6.10.0070.05320.45
5.6.00.0100.05020.42

preferences:
171.03 ms | 403 KiB | 5 Q