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(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.0090.00720.48
8.5.00.0100.01221.97
8.4.150.0030.00014.05
8.4.140.0130.00918.19
8.4.130.0130.00818.50
8.4.120.0130.00624.70
8.4.110.0090.01022.68
8.4.100.0120.00819.57
8.4.90.0030.00720.90
8.4.80.0100.00818.97
8.4.70.0060.00318.58
8.4.60.0080.00419.35
8.4.50.0090.01119.10
8.4.40.0130.00319.78
8.4.30.0100.01019.49
8.4.20.0100.01017.96
8.4.10.0090.00019.79
8.3.280.0130.00718.55
8.3.270.0120.00917.30
8.3.260.0130.00717.22
8.3.250.0090.01019.24
8.3.240.0120.00717.75
8.3.230.0140.00717.26
8.3.220.0110.00619.58
8.3.210.0130.00818.75
8.3.200.0060.00316.82
8.3.190.0130.01017.50
8.3.180.0090.01017.43
8.3.170.0000.00919.35
8.3.160.0120.00917.34
8.3.150.0060.01317.61
8.3.140.0080.00017.46
8.3.130.0140.00716.91
8.3.120.0140.00719.04
8.3.110.0090.00020.94
8.3.100.0080.00016.91
8.3.90.0080.00026.77
8.3.80.0100.00017.97
8.3.70.0040.01516.75
8.3.60.0090.00618.68
8.3.50.0110.00722.15
8.3.40.0080.00819.08
8.3.30.0060.00919.35
8.3.20.0000.00819.15
8.3.10.0000.00822.54
8.3.00.0050.00222.23
8.2.290.0110.00820.67
8.2.280.0020.00618.80
8.2.270.0060.01217.92
8.2.260.0030.00517.22
8.2.250.0060.00318.88
8.2.240.0060.00317.96
8.2.230.0070.00722.58
8.2.220.0060.00324.06
8.2.210.0030.00526.77
8.2.200.0000.00917.25
8.2.190.0070.01017.13
8.2.180.0070.01417.00
8.2.170.0070.01022.96
8.2.160.0070.00722.76
8.2.150.0050.00524.18
8.2.140.0040.00424.66
8.2.130.0040.00420.14
8.2.120.0060.00326.35
8.2.110.0100.00020.73
8.2.100.0100.00318.41
8.2.90.0050.00318.00
8.2.80.0000.00819.14
8.2.70.0080.00017.88
8.2.60.0000.00818.00
8.2.50.0040.00418.00
8.2.40.0030.00621.13
8.2.30.0040.00421.39
8.2.20.0040.00418.45
8.2.10.0040.00418.60
8.2.00.0080.00018.08
8.1.330.0040.00622.76
8.1.320.0090.01016.45
8.1.310.0090.00018.69
8.1.300.0090.00018.89
8.1.290.0030.00630.84
8.1.280.0100.01025.92
8.1.270.0040.00424.16
8.1.260.0030.00628.09
8.1.250.0000.00828.09
8.1.240.0000.01024.17
8.1.230.0070.00421.29
8.1.220.0040.00419.20
8.1.210.0030.00518.77
8.1.200.0050.00317.73
8.1.190.0040.00417.60
8.1.180.0040.00419.54
8.1.170.0000.00818.78
8.1.160.0050.00324.30
8.1.150.0080.00320.99
8.1.140.0000.00919.91
8.1.130.0080.00018.15
8.1.120.0040.00417.89
8.1.110.0000.00717.81
8.1.100.0000.00717.75
8.1.90.0040.00417.85
8.1.80.0050.00217.80
8.1.70.0030.00317.87
8.1.60.0000.00718.08
8.1.50.0040.00418.01
8.1.40.0040.00417.91
8.1.30.0040.00418.04
8.1.20.0000.00818.05
8.1.10.0000.00818.07
8.1.00.0040.00417.89
8.0.300.0000.00818.77
8.0.290.0040.00717.25
8.0.280.0000.00718.99
8.0.270.0050.00217.77
8.0.260.0000.00717.60
8.0.250.0000.00717.47
8.0.240.0050.00217.46
8.0.230.0000.00817.43
8.0.220.0030.00617.40
8.0.210.0030.00517.35
8.0.200.0000.00717.43
8.0.190.0040.00417.43
8.0.180.0000.00717.33
8.0.170.0000.00817.26
8.0.160.0040.00417.36
8.0.150.0000.00717.23
8.0.140.0070.00017.28
8.0.130.0060.00013.68
8.0.120.0030.00517.18
8.0.110.0050.00317.26
8.0.100.0000.00717.18
8.0.90.0040.00417.04
8.0.80.0000.01417.12
8.0.70.0040.00417.12
8.0.60.0000.00817.16
8.0.50.0080.00017.31
8.0.30.0100.01017.39
8.0.20.0140.00517.44
8.0.10.0040.00417.23
8.0.00.0030.01516.84
7.4.330.0000.00615.55
7.4.320.0000.00616.96
7.4.300.0000.00617.02
7.4.290.0040.00417.16
7.4.280.0040.00417.11
7.4.270.0070.00016.94
7.4.260.0050.00317.08
7.4.250.0040.00416.92
7.4.240.0070.00017.02
7.4.230.0040.00416.83
7.4.220.0160.00716.85
7.4.210.0100.00416.75
7.4.200.0040.00417.12
7.4.160.0060.01016.83
7.4.150.0090.01217.40
7.4.140.0080.01017.86
7.4.130.0080.01016.86
7.4.120.0120.00516.77
7.4.110.0090.00916.87
7.4.100.0130.00616.76
7.4.90.0090.00916.61
7.4.80.0120.00619.39
7.4.70.0090.00616.86
7.4.60.0130.00916.71
7.4.50.0060.00917.05
7.4.40.0070.01016.95
7.4.30.0140.00616.66
7.4.00.0060.00615.47
7.3.330.0030.00313.58
7.3.320.0060.00013.81
7.3.310.0030.00316.84
7.3.300.0040.00416.82
7.3.290.0070.00016.83
7.3.280.0090.01016.65
7.3.270.0130.00717.40
7.3.260.0090.00816.88
7.3.250.0080.01216.80
7.3.240.0110.01016.78
7.3.230.0170.00016.62
7.3.210.0090.00916.59
7.3.200.0130.01017.00
7.3.190.0090.00616.77
7.3.180.0090.00816.90
7.3.170.0080.00816.79
7.3.160.0150.00616.86
7.3.00.0090.00617.22
7.2.330.0120.00616.83
7.2.320.0130.00516.96
7.2.310.0120.00616.89
7.2.300.0140.00316.90
7.2.290.0140.00316.87
7.2.130.0090.00617.27
7.2.120.0030.01017.28
7.2.110.0000.01517.27
7.2.100.0090.00017.39
7.2.90.0070.01117.37
7.2.80.0030.00717.43
7.2.70.0040.00717.45
7.2.60.0090.00617.12
7.2.50.0070.00717.05
7.2.40.0060.00317.36
7.2.30.0120.00017.05
7.2.20.0000.01417.40
7.2.10.0160.00017.34
7.2.00.0050.01118.34
7.1.250.0090.00415.94
7.1.240.0040.01115.62
7.1.230.0000.01016.31
7.1.220.0080.00315.98
7.1.210.0030.01016.08
7.1.200.0000.01015.83
7.1.190.0060.00616.09
7.1.180.0070.00316.16
7.1.170.0070.00715.96
7.1.160.0110.00416.00
7.1.150.0110.00315.97
7.1.140.0060.00315.92
7.1.130.0030.00616.20
7.1.120.0080.00416.00
7.1.110.0140.00015.71
7.1.100.0080.00315.91
7.1.90.0110.00416.15
7.1.80.0000.00816.15
7.1.70.0010.00716.73
7.1.60.0020.01216.84
7.1.50.0150.00315.79
7.1.40.0030.00616.01
7.1.30.0060.00916.08
7.1.20.0080.00415.88
7.1.10.0030.01015.82
7.1.00.0070.03819.34
7.0.330.0080.00515.79
7.0.320.0030.00715.81
7.0.310.0100.00315.49
7.0.300.0000.01215.73
7.0.290.0040.01115.75
7.0.280.0030.00915.57
7.0.270.0070.00715.37
7.0.260.0060.00615.89
7.0.250.0060.00315.79
7.0.240.0070.00315.74
7.0.230.0060.00615.92
7.0.220.0000.01115.62
7.0.210.0030.01015.76
7.0.200.0160.00415.26
7.0.190.0060.00915.58
7.0.180.0120.00015.73
7.0.170.0030.00615.91
7.0.160.0100.00316.00
7.0.150.0060.00915.64
7.0.140.0000.01115.66
7.0.130.0090.00315.70
7.0.120.0090.02818.91
7.0.110.0030.03719.01
7.0.100.0050.03318.94
7.0.90.0100.03119.00
7.0.80.0050.03618.87
7.0.70.0080.03019.07
7.0.60.0080.03819.07
7.0.50.0050.03519.05
7.0.40.0050.03418.11
7.0.30.0050.03418.16
7.0.20.0030.03318.05
7.0.10.0050.03517.95
7.0.00.0070.03317.94
5.6.380.0000.01314.38
5.6.370.0000.01014.64
5.6.360.0000.01014.57
5.6.350.0030.01014.50
5.6.340.0090.00314.76
5.6.330.0060.00614.75
5.6.320.0110.00714.86
5.6.310.0110.00414.62
5.6.300.0030.01014.64
5.6.290.0030.01014.45
5.6.280.0070.00714.43
5.6.270.0050.03217.82
5.6.260.0100.03017.91
5.6.250.0020.03517.89
5.6.240.0070.04417.84
5.6.230.0050.04018.00
5.6.220.0020.03417.85
5.6.210.0070.03517.84
5.6.200.0070.04217.89
5.6.190.0050.04517.90
5.6.180.0050.03717.94
5.6.170.0100.03317.90
5.6.160.0080.03117.68
5.6.150.0100.04217.76
5.6.140.0120.03517.71
5.6.130.0050.03217.92
5.6.120.0080.03318.01
5.6.110.0110.02817.87
5.6.100.0110.02817.75
5.6.90.0070.03617.92
5.6.80.0060.04017.57
5.6.70.0050.03417.45
5.6.60.0080.03317.59
5.6.50.0110.03717.50
5.6.40.0040.03417.47
5.6.30.0050.03317.54
5.6.20.0120.02817.46
5.6.10.0040.03117.41
5.6.00.0100.03917.45

preferences:
37.23 ms | 403 KiB | 5 Q