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(min(1, sqrt($stepOne))); return $calculatedDistance = 6370996.81 * $stepTwo; } echo "\n"; echo calculateSignDistance(121.40233369999998,31.2014966,121.44552099999998,31.22323799999999); /** *求两个已知经纬度之间的距离,单位为千米 *@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 = ($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(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.0110.00820.51
8.5.00.0130.01021.94
8.4.150.0020.00114.05
8.4.140.0160.00517.81
8.4.130.0050.00418.04
8.4.120.0120.00824.74
8.4.110.0120.00823.07
8.4.100.0110.01019.27
8.4.90.0090.00220.91
8.4.80.0120.00818.99
8.4.70.0060.00218.46
8.4.60.0100.00319.21
8.4.50.0120.00618.92
8.4.40.0210.00020.07
8.4.30.0030.01618.23
8.4.20.0150.00618.40
8.4.10.0060.00319.73
8.3.280.0140.00718.59
8.3.270.0140.00617.06
8.3.260.0130.00817.06
8.3.250.0110.00819.25
8.3.240.0120.00717.77
8.3.230.0110.00416.95
8.3.220.0090.01019.50
8.3.210.0120.00818.74
8.3.200.0060.00517.13
8.3.190.0160.00817.40
8.3.180.0090.01017.59
8.3.170.0040.00421.18
8.3.160.0180.00017.72
8.3.150.0070.01117.74
8.3.140.0090.00917.12
8.3.130.0060.00318.65
8.3.120.0100.00619.46
8.3.110.0030.00620.94
8.3.100.0000.01217.26
8.3.90.0090.00026.77
8.3.80.0090.00017.97
8.3.70.0150.00317.11
8.3.60.0100.01317.13
8.3.50.0110.00721.52
8.3.40.0130.00619.20
8.3.30.0120.00319.18
8.3.20.0080.00019.13
8.3.10.0040.00422.40
8.3.00.0000.00824.15
8.2.290.0110.00720.70
8.2.280.0060.00218.56
8.2.270.0110.00717.48
8.2.260.0080.00017.31
8.2.250.0030.00718.66
8.2.240.0070.00317.51
8.2.230.0060.00322.58
8.2.220.0080.00024.06
8.2.210.0080.00026.77
8.2.200.0060.00317.25
8.2.190.0070.00716.88
8.2.180.0070.01417.00
8.2.170.0100.00622.96
8.2.160.0000.01422.45
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0000.00820.20
8.2.120.0050.00326.35
8.2.110.0060.00322.44
8.2.100.0100.00318.22
8.2.90.0040.00419.57
8.2.80.0050.00517.97
8.2.70.0000.00818.13
8.2.60.0030.00518.17
8.2.50.0060.00318.10
8.2.40.0080.00021.10
8.2.30.0080.00021.57
8.2.20.0070.00018.66
8.2.10.0000.00818.51
8.2.00.0040.00418.12
8.1.330.0060.00322.55
8.1.320.0120.00916.75
8.1.310.0080.00019.00
8.1.300.0160.00319.15
8.1.290.0030.00630.84
8.1.280.0070.00725.92
8.1.270.0040.00424.21
8.1.260.0040.00428.09
8.1.250.0070.00028.09
8.1.240.0000.01021.36
8.1.230.0070.00419.72
8.1.220.0000.00818.14
8.1.210.0080.00018.77
8.1.200.0030.00617.98
8.1.190.0030.00517.75
8.1.180.0090.00018.10
8.1.170.0080.00019.31
8.1.160.0000.00724.28
8.1.150.0030.00719.18
8.1.140.0040.00420.19
8.1.130.0000.00718.02
8.1.120.0040.00417.83
8.1.110.0040.00417.85
8.1.100.0050.00217.75
8.1.90.0070.00017.85
8.1.80.0040.00417.80
8.1.70.0030.00317.93
8.1.60.0050.00217.94
8.1.50.0080.00017.97
8.1.40.0040.00417.98
8.1.30.0040.00418.07
8.1.20.0000.00718.01
8.1.10.0030.00617.89
8.1.00.0030.00617.91
8.0.300.0000.00820.85
8.0.290.0000.00817.13
8.0.280.0040.00419.08
8.0.270.0040.00417.66
8.0.260.0000.00617.61
8.0.250.0070.00017.34
8.0.240.0040.00417.42
8.0.230.0040.00417.52
8.0.220.0040.00417.30
8.0.210.0000.00717.22
8.0.200.0000.00717.39
8.0.190.0080.00017.45
8.0.180.0000.00717.32
8.0.170.0040.00417.22
8.0.160.0050.00317.35
8.0.150.0040.00417.25
8.0.140.0040.00417.29
8.0.130.0030.00313.77
8.0.120.0080.00017.18
8.0.110.0030.00617.33
8.0.100.0040.00417.15
8.0.90.0000.00717.15
8.0.80.0060.01617.18
8.0.70.0080.00017.44
8.0.60.0030.00417.36
8.0.50.0000.00717.50
8.0.30.0110.00617.25
8.0.20.0090.01117.43
8.0.10.0000.00917.51
8.0.00.0090.00917.16
7.4.330.0000.00515.55
7.4.320.0030.00316.98
7.4.300.0000.00617.09
7.4.290.0070.00016.99
7.4.280.0000.00817.10
7.4.270.0030.00517.07
7.4.260.0070.00016.95
7.4.250.0000.00817.01
7.4.240.0030.00317.05
7.4.230.0000.00716.99
7.4.220.0040.01416.84
7.4.210.0080.00716.85
7.4.200.0000.00817.27
7.4.160.0060.01016.78
7.4.150.0070.01117.40
7.4.140.0100.00817.86
7.4.130.0130.00816.82
7.4.120.0090.00816.79
7.4.110.0120.00816.88
7.4.100.0070.01016.75
7.4.90.0210.00616.79
7.4.80.0090.00919.39
7.4.70.0100.01016.75
7.4.60.0060.01216.79
7.4.50.0000.01516.84
7.4.40.0070.01016.84
7.4.30.0140.00716.82
7.4.10.0100.00715.36
7.4.00.0060.00915.13
7.3.330.0030.00313.84
7.3.320.0000.00613.82
7.3.310.0000.00716.88
7.3.300.0040.00416.80
7.3.290.0070.00016.79
7.3.280.0080.01016.68
7.3.270.0090.00917.40
7.3.260.0110.00716.81
7.3.250.0070.01016.65
7.3.240.0090.01616.66
7.3.230.0060.01116.94
7.3.210.0150.00316.69
7.3.200.0150.00716.98
7.3.190.0070.01016.81
7.3.180.0040.01816.77
7.3.170.0140.00416.63
7.3.160.0100.01416.65
7.3.130.0100.00815.34
7.3.120.0040.01415.15
7.3.110.0080.01015.25
7.3.100.0050.00915.20
7.3.90.0100.00515.06
7.3.80.0070.00215.20
7.3.70.0050.00815.15
7.3.60.0040.00815.31
7.3.50.0030.01015.22
7.3.40.0040.00715.09
7.3.30.0010.01015.12
7.3.20.0040.00816.98
7.3.10.0040.00917.11
7.3.00.0050.00717.18
7.2.330.0150.00917.00
7.2.320.0120.00616.80
7.2.310.0100.00716.76
7.2.300.0120.00617.01
7.2.290.0100.00716.70
7.2.260.0070.01115.26
7.2.250.0100.00815.38
7.2.240.0060.01115.48
7.2.230.0060.01015.40
7.2.220.0070.00715.45
7.2.210.0020.00915.29
7.2.200.0080.00815.31
7.2.190.0050.00515.18
7.2.180.0110.00215.18
7.2.170.0080.00515.26
7.2.160.0070.00715.55
7.2.150.0060.00717.06
7.2.140.0030.01116.96
7.2.130.0060.00917.21
7.2.120.0030.01017.36
7.2.110.0080.00717.04
7.2.100.0030.01217.33
7.2.90.0070.00917.19
7.2.80.0030.01017.06
7.2.70.0050.00817.30
7.2.60.0070.00617.06
7.2.50.0020.01317.25
7.2.40.0090.00317.22
7.2.30.0030.00817.30
7.2.20.0070.00717.21
7.2.10.0080.00917.34
7.2.00.0070.00717.87
7.1.330.0050.00816.15
7.1.320.0080.00616.21
7.1.310.0080.00516.17
7.1.300.0000.01216.06
7.1.290.0000.01116.01
7.1.280.0050.00615.88
7.1.270.0000.01115.91
7.1.260.0060.00716.00
7.1.250.0020.00916.17
7.1.240.0090.00715.95
7.1.230.0090.00915.88
7.1.220.0050.00716.06
7.1.210.0000.01416.17
7.1.200.0000.01316.14
7.1.190.0050.00716.16
7.1.180.0060.00515.87
7.1.170.0080.00716.02
7.1.160.0050.00516.08
7.1.150.0070.00716.19
7.1.140.0090.00515.87
7.1.130.0040.00816.04
7.1.120.0070.00516.09
7.1.110.0080.00515.94
7.1.100.0050.00916.31
7.1.90.0050.00516.08
7.1.80.0040.00916.08
7.1.70.0040.00616.51
7.1.60.0060.00616.33
7.1.50.0040.00915.96
7.1.40.0050.00815.88
7.1.30.0030.01015.75
7.1.20.0100.00516.16
7.1.10.0030.00716.12
7.1.00.0060.03018.18
7.0.330.0090.00515.84
7.0.320.0030.00715.43
7.0.310.0060.00915.44
7.0.300.0060.00515.79
7.0.290.0030.00915.49
7.0.280.0080.00415.64
7.0.270.0030.01215.88
7.0.260.0080.00315.78
7.0.250.0050.00715.48
7.0.240.0020.01015.84
7.0.230.0050.00815.90
7.0.220.0030.01015.64
7.0.210.0030.01015.96
7.0.200.0150.00515.46
7.0.190.0060.00815.60
7.0.180.0060.00315.75
7.0.170.0030.00615.61
7.0.160.0110.00315.58
7.0.150.0060.00415.77
7.0.140.0030.00815.63
7.0.130.0060.00615.64
7.0.120.0070.02817.92
7.0.110.0090.02517.97
7.0.100.0090.02217.90
7.0.90.0070.02517.99
7.0.80.0070.02317.82
7.0.70.0090.02317.95
7.0.60.0070.02417.85
7.0.50.0050.02217.82
7.0.40.0090.02516.69
7.0.30.0090.02316.64
7.0.20.0080.02116.57
7.0.10.0100.02016.62
7.0.00.0100.02316.52
5.6.400.0050.00714.72
5.6.390.0050.00614.65
5.6.380.0110.00414.62
5.6.370.0080.00214.45
5.6.360.0050.00814.72
5.6.350.0020.01214.43
5.6.340.0020.00814.69
5.6.330.0060.00614.56
5.6.320.0050.00814.78
5.6.310.0050.00814.60
5.6.300.0070.00614.50
5.6.290.0080.00614.51
5.6.280.0040.01114.43
5.6.270.0050.02616.78
5.6.260.0100.02716.62
5.6.250.0050.02516.83
5.6.240.0070.02216.75
5.6.230.0080.02416.75
5.6.220.0050.02316.96
5.6.210.0080.02316.74
5.6.200.0100.02116.83
5.6.190.0030.02916.79
5.6.180.0070.02316.98
5.6.170.0050.02416.87
5.6.160.0070.02416.65
5.6.150.0060.02616.69
5.6.140.0070.02416.93
5.6.130.0090.02316.79
5.6.120.0080.02416.82
5.6.110.0080.02316.74
5.6.100.0040.03216.95
5.6.90.0090.02216.61
5.6.80.0060.02516.54
5.6.70.0060.02216.58
5.6.60.0090.02216.52
5.6.50.0070.02616.52
5.6.40.0050.02516.59
5.6.30.0060.02516.42
5.6.20.0050.03116.75
5.6.10.0110.02316.63
5.6.00.0090.02416.51

preferences:
23.74 ms | 403 KiB | 5 Q