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 = 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(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.0100.00720.47
8.5.00.0150.00621.74
8.4.150.0030.00014.05
8.4.140.0090.01317.87
8.4.130.0050.00418.15
8.4.120.0050.00320.99
8.4.110.0110.00923.13
8.4.100.0120.00817.89
8.4.90.0130.00819.34
8.4.80.0090.01120.73
8.4.70.0180.00418.39
8.4.60.0040.00519.59
8.4.50.0120.00719.28
8.4.40.0170.00319.82
8.4.30.0150.00419.79
8.4.20.0030.00618.19
8.4.10.0100.00619.78
8.3.280.0100.01220.35
8.3.270.0140.00717.16
8.3.260.0120.00717.00
8.3.250.0100.00919.17
8.3.240.0050.00316.77
8.3.230.0040.00417.20
8.3.220.0120.00521.15
8.3.210.0090.00918.74
8.3.200.0060.00317.32
8.3.190.0100.00817.49
8.3.180.0040.01117.57
8.3.170.0150.00321.19
8.3.160.0100.00717.94
8.3.150.0130.00617.66
8.3.140.0080.00017.14
8.3.130.0060.00318.85
8.3.120.0000.01019.36
8.3.110.0000.00920.94
8.3.100.0090.00017.03
8.3.90.0080.00826.77
8.3.80.0060.00317.97
8.3.70.0000.01517.13
8.3.60.0070.01117.24
8.3.50.0070.01222.12
8.3.40.0110.00419.22
8.3.30.0070.00719.03
8.3.20.0040.00418.98
8.3.10.0040.00422.23
8.3.00.0000.00722.31
8.2.290.0110.00920.67
8.2.280.0030.00418.85
8.2.270.0000.01817.59
8.2.260.0030.00517.08
8.2.250.0080.00018.78
8.2.240.0080.00017.97
8.2.230.0060.00322.58
8.2.220.0100.00024.06
8.2.210.0060.01226.77
8.2.200.0080.00016.88
8.2.190.0110.00717.00
8.2.180.0060.00917.00
8.2.170.0070.01022.96
8.2.160.0070.00722.77
8.2.150.0090.00024.18
8.2.140.0060.00324.66
8.2.130.0030.00520.16
8.2.120.0000.00826.35
8.2.110.0040.00919.64
8.2.100.0120.00418.41
8.2.90.0060.00319.55
8.2.80.0080.00017.97
8.2.70.0060.00317.88
8.2.60.0000.00818.30
8.2.50.0040.00418.10
8.2.40.0040.00420.92
8.2.30.0000.00921.45
8.2.20.0030.00618.46
8.2.10.0040.00418.50
8.2.00.0050.00318.13
8.1.330.0110.01120.83
8.1.320.0120.00618.67
8.1.310.0120.00619.06
8.1.300.0080.00018.80
8.1.290.0040.00430.84
8.1.280.0070.01425.92
8.1.270.0040.00424.41
8.1.260.0000.00728.09
8.1.250.0070.00028.09
8.1.240.0060.00324.17
8.1.230.0080.00817.75
8.1.220.0000.00918.16
8.1.210.0030.00618.77
8.1.200.0030.00617.63
8.1.190.0040.00419.49
8.1.180.0060.00318.10
8.1.170.0000.00819.29
8.1.160.0000.00722.48
8.1.150.0040.00719.20
8.1.140.0080.00020.03
8.1.130.0040.00417.98
8.1.120.0040.00417.82
8.1.110.0030.00617.86
8.1.100.0070.00017.75
8.1.90.0000.00817.76
8.1.80.0050.00217.89
8.1.70.0040.00417.79
8.1.60.0040.00417.98
8.1.50.0040.00417.98
8.1.40.0000.00818.02
8.1.30.0000.00818.10
8.1.20.0090.00018.02
8.1.10.0040.00417.89
8.1.00.0000.00917.85
8.0.300.0050.00318.77
8.0.290.0000.00817.13
8.0.280.0040.00418.79
8.0.270.0000.00817.71
8.0.260.0030.00317.77
8.0.250.0070.00017.36
8.0.240.0000.00717.52
8.0.230.0070.00017.27
8.0.220.0040.00417.29
8.0.210.0030.00317.41
8.0.200.0000.00717.36
8.0.190.0040.00417.36
8.0.180.0070.00317.21
8.0.170.0040.00417.37
8.0.160.0080.00017.31
8.0.150.0000.00817.15
8.0.140.0030.00517.28
8.0.130.0000.00613.79
8.0.120.0030.00517.29
8.0.110.0000.00717.27
8.0.100.0080.00017.31
8.0.90.0070.00017.24
8.0.80.0040.01117.24
8.0.70.0080.00017.41
8.0.60.0070.00017.16
8.0.50.0040.00417.50
8.0.30.0070.01017.11
8.0.20.0080.01217.42
8.0.10.0040.00417.42
8.0.00.0060.01116.86
7.4.330.0030.00315.55
7.4.320.0000.00616.90
7.4.300.0060.00016.96
7.4.290.0050.00317.06
7.4.280.0060.00317.05
7.4.270.0030.00317.07
7.4.260.0030.00317.05
7.4.250.0000.00716.95
7.4.240.0000.00817.05
7.4.230.0070.00016.74
7.4.220.0050.01116.71
7.4.210.0090.00916.94
7.4.200.0000.00717.07
7.4.160.0070.00916.77
7.4.150.0070.01017.40
7.4.140.0090.00817.86
7.4.130.0130.00716.77
7.4.120.0140.00616.91
7.4.110.0160.00016.77
7.4.100.0080.00816.81
7.4.90.0150.00316.93
7.4.80.0030.01419.39
7.4.70.0100.00616.75
7.4.60.0040.01416.67
7.4.50.0040.00617.16
7.4.40.0130.01016.78
7.4.30.0060.01616.67
7.4.00.0010.01315.19
7.3.330.0000.00513.77
7.3.320.0060.00013.64
7.3.310.0070.00016.86
7.3.300.0030.00316.80
7.3.290.0070.00016.64
7.3.280.0100.00916.67
7.3.270.0110.00717.40
7.3.260.0120.00816.88
7.3.250.0100.00816.76
7.3.240.0100.01016.64
7.3.230.0110.00616.88
7.3.210.0040.01716.92
7.3.200.0040.01216.90
7.3.190.0090.00916.63
7.3.180.0130.00916.70
7.3.170.0030.01616.63
7.3.160.0100.01416.89
7.3.120.0090.00615.20
7.3.110.0030.01414.85
7.3.100.0000.01415.23
7.3.90.0060.00315.23
7.3.80.0040.00715.20
7.3.70.0080.00515.20
7.3.60.0060.01214.93
7.3.50.0030.00915.23
7.3.40.0060.00915.38
7.3.30.0030.01015.36
7.3.20.0100.00316.98
7.3.10.0040.01116.87
7.3.00.0040.00717.09
7.2.330.0000.01816.68
7.2.320.0100.01016.98
7.2.310.0100.00616.80
7.2.300.0120.01216.79
7.2.290.0140.00316.64
7.2.250.0030.01715.27
7.2.240.0030.01315.40
7.2.230.0090.00915.24
7.2.220.0040.00815.29
7.2.210.0060.00615.26
7.2.200.0120.00615.36
7.2.190.0060.00915.44
7.2.180.0060.01015.40
7.2.170.0030.00915.57
7.2.60.0050.00817.19
7.1.330.0060.00915.95
7.1.320.0090.00616.20
7.1.310.0030.00716.18
7.1.300.0000.01315.85
7.1.290.0050.00516.08
7.1.280.0030.01015.82
7.1.270.0070.00716.07
7.1.260.0000.01415.86
7.1.200.0090.00316.03
7.1.70.0060.00317.12
7.1.60.0040.00717.54
7.1.00.0000.08022.75
7.0.200.0350.00314.90
7.0.120.0070.05722.28
7.0.110.0170.05722.39
7.0.100.0070.08722.21
7.0.90.0130.05322.20
7.0.80.0130.05322.29
7.0.70.0200.07022.28
7.0.60.0000.06722.25
7.0.50.0100.05722.26
7.0.40.0030.06022.43
7.0.30.0130.05322.34
7.0.20.0170.05322.29
7.0.10.0100.07722.48
7.0.00.0070.06022.26
5.6.270.0070.07721.36
5.6.260.0130.07321.43
5.6.250.0100.07321.42
5.6.240.0100.06321.07
5.6.230.0030.07321.07
5.6.220.0130.05021.25
5.6.210.0100.05321.09
5.6.200.0000.06721.07
5.6.190.0070.06721.07
5.6.180.0130.05321.30
5.6.170.0000.06321.18
5.6.160.0130.05321.05
5.6.150.0130.05321.18
5.6.140.0200.05321.09
5.6.130.0030.06321.08
5.6.120.0100.05721.23
5.6.110.0100.05721.27
5.6.100.0100.05721.09
5.6.90.0100.05720.97
5.6.80.0000.06320.68
5.6.70.0170.04720.67
5.6.60.0070.05720.46
5.6.50.0100.07020.61
5.6.40.0130.05720.59
5.6.30.0100.05020.65
5.6.20.0230.05020.64
5.6.10.0100.05020.57
5.6.00.0130.05020.42

preferences:
23.58 ms | 403 KiB | 5 Q