3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Coordinate { /** @var float $latitudeRadians */ protected $latitudeRadians; /** @var float $longitudeRadians */ protected $longitudeRadians; /** * Constructor. * * @param float $latitudeRadians * @param float $latitudeRadians */ public function __construct( float $latitudeRadians, float $longitudeRadians ) { $this->latitudeRadians = $latitudeRadians; $this->longitudeRadians = $longitudeRadians; } /** * Create a Coordinate object from latitude and longitude given in degrees. * * @param float $latitudeDegrees * @param float $longitudeDegrees * * @return static */ public static function fromDegrees(float $latitudeDegrees, float $longitudeDegrees) { return new static( $latitudeDegrees * M_PI / 180, $longitudeDegrees * M_PI / 180 ); } /** * Get the coordinate's latitude, measured in degrees. * * @return float */ public function latitudeDegrees() : float { return $this->latitudeRadians * 180 / M_PI; } /** * Get the coordinate's latitude, measured in radians. * * @return float */ public function latitudeRadians() : float { return $this->latitudeRadians; } /** * Get the coordinate's longitude, measured in degrees. * * @return float */ public function longitudeDegrees() : float { return $this->longitudeRadians * 180 / M_PI; } /** * Get the coordinate's longitude, measured in radians. * * @return float */ public function longitudeRadians() : float { return $this->longitudeRadians; } /** * Is this coordinate equivalent to another? * * @param static $other * * @return bool */ public function equals(self $other) : bool { return $this->latitudeRadians() === $other->latitudeRadians() && $this->longitudeRadians() === $other->longitudeRadians() ; } /** * Calculate the distance between this and another coordinate, in kilometers. * * @param static $other * * @return float */ public function distanceKilometers(self $other) : float { // Haversine formula for great-circle distance. $earthRadiusKilometers = 6371; $deltaLatitudeRadians = $this->latitudeRadians() - $other->latitudeRadians(); $deltaLongitudeRadians = $this->longitudeRadians() - $other->longitudeRadians(); $a = sin($deltaLatitudeRadians / 2) ** 2 + cos($this->latitudeRadians()) * cos($other->latitudeRadians()) * sin($deltaLongitudeRadians / 2) ** 2 ; $c = 2 * asin(sqrt($a)); return $c * $earthRadiusKilometers; } } $latitudeWorkDegrees = 40.981123; $longitudeWorkDegrees = -74.121752; $latitudeHomeDegrees = 41.184084; $longitudeHomeDegrees = -74.555852; $latitudeWorkRadians = deg2rad($latitudeWorkDegrees); $longitudeWorkRadians = deg2rad($longitudeWorkDegrees); $latitudeHomeRadians = deg2rad($latitudeHomeDegrees); $longitudeHomeRadians = deg2rad($longitudeHomeDegrees); $coordinateWork = new Coordinate($latitudeWorkRadians, $longitudeWorkRadians); $coordinateHome = new Coordinate($latitudeHomeRadians, $longitudeHomeRadians); $distance = $coordinateWork->distanceKilometers($coordinateHome); echo $distance;

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.0120.00317.00
8.3.50.0040.01218.64
8.3.40.0090.00619.34
8.3.30.0080.00819.29
8.3.20.0080.00019.48
8.3.10.0040.00422.13
8.3.00.0060.00322.75
8.2.180.0110.00416.98
8.2.170.0140.00022.96
8.2.160.0140.00021.70
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0050.00322.76
8.2.120.0000.00826.35
8.2.110.0060.00322.46
8.2.100.0070.00418.16
8.2.90.0060.00318.28
8.2.80.0000.01018.41
8.2.70.0060.00318.00
8.2.60.0040.00418.30
8.2.50.0040.00818.10
8.2.40.0030.00620.80
8.2.30.0040.00419.79
8.2.20.0000.00718.24
8.2.10.0040.00418.54
8.2.00.0040.00418.45
8.1.280.0070.01025.92
8.1.270.0080.00024.12
8.1.260.0080.00028.09
8.1.250.0070.00028.09
8.1.240.0120.00622.77
8.1.230.0000.01221.32
8.1.220.0000.00818.02
8.1.210.0060.00319.42
8.1.200.0060.00317.60
8.1.190.0060.00317.73
8.1.180.0040.00418.10
8.1.170.0080.00019.21
8.1.160.0040.00422.40
8.1.150.0070.00019.40
8.1.140.0000.00819.82
8.1.130.0080.00017.96
8.1.120.0030.00317.82
8.1.110.0000.00817.73
8.1.100.0040.00417.73
8.1.90.0040.00417.75
8.1.80.0030.00617.75
8.1.70.0030.00717.77
8.1.60.0090.00017.96
8.1.50.0050.00317.79
8.1.40.0000.00817.93
8.1.30.0000.00818.03
8.1.20.0080.00018.16
8.1.10.0000.00817.90
8.1.00.0000.01017.81
8.0.300.0040.00420.41
8.0.290.0000.00917.38
8.0.280.0030.00318.98
8.0.270.0000.00717.70
8.0.260.0000.01017.50
8.0.250.0040.00417.43
8.0.240.0070.00017.43
8.0.230.0080.00017.43
8.0.220.0030.00317.43
8.0.210.0000.00717.34
8.0.200.0060.00017.33
8.0.190.0040.00417.40
8.0.180.0040.00417.39
8.0.170.0000.00817.38
8.0.160.0080.00017.35
8.0.150.0000.00817.33
8.0.140.0060.00617.29
8.0.130.0030.00313.73
8.0.120.0000.00817.27
8.0.110.0080.00017.29
8.0.100.0000.00817.23
8.0.90.0000.00717.30
8.0.80.0130.00717.11
8.0.70.0080.00017.12
8.0.60.0000.00717.20
8.0.50.0000.00717.13
8.0.30.0050.01017.42
8.0.20.0100.00817.40
8.0.10.0000.00817.45
8.0.00.0090.01317.26
7.4.330.0070.00015.08
7.4.320.0000.00617.03
7.4.300.0000.00716.91
7.4.290.0030.00316.88
7.4.280.0070.00016.88
7.4.270.0030.00316.87
7.4.260.0040.00416.89
7.4.250.0000.00716.95
7.4.240.0040.00417.01
7.4.230.0000.00717.01
7.4.220.0060.01616.84
7.4.210.0100.01016.71
7.4.200.0000.00716.88
7.4.160.0030.01216.82
7.4.150.0070.01017.40
7.4.140.0090.00917.86
7.4.130.0130.00716.86
7.4.120.0090.01016.89
7.4.110.0120.00616.66
7.4.100.0100.00716.74
7.4.90.0110.00916.66
7.4.80.0100.00619.39
7.4.70.0030.01316.75
7.4.60.0140.00416.68
7.4.50.0130.00316.80
7.4.40.0110.00616.79
7.4.30.0030.01716.66
7.4.10.0110.00515.14
7.4.00.0080.00915.22
7.3.330.0030.00313.63
7.3.320.0050.00013.82
7.3.310.0030.00516.74
7.3.300.0040.00416.65
7.3.290.0130.00216.57
7.3.280.0110.00816.57
7.3.270.0120.00617.40
7.3.260.0090.00916.70
7.3.250.0120.00516.63
7.3.240.0100.00816.56
7.3.230.0070.01716.64
7.3.210.0130.00316.59
7.3.200.0170.00016.62
7.3.190.0080.00816.82
7.3.180.0170.00616.51
7.3.170.0070.01116.63
7.3.160.0180.00716.78
7.3.130.0030.01415.14
7.3.120.0050.01415.13
7.3.110.0090.00915.13
7.3.100.0070.00715.27
7.3.90.0070.00815.17
7.3.80.0000.01115.15
7.3.70.0040.01215.21
7.3.60.0030.01015.28
7.3.50.0030.01015.23
7.3.40.0080.00614.95
7.3.30.0020.00715.21
7.3.20.0070.01016.89
7.3.10.0020.01316.82
7.3.00.0070.00717.15
7.2.330.0090.00916.81
7.2.320.0100.00716.82
7.2.310.0060.00916.83
7.2.300.0050.01317.01
7.2.290.0100.00717.12
7.2.260.0100.00815.45
7.2.250.0050.01515.48
7.2.240.0090.00615.28
7.2.230.0030.01115.28
7.2.220.0070.00715.52
7.2.210.0050.00715.31
7.2.200.0030.01015.49
7.2.190.0030.01015.28
7.2.180.0090.00615.37
7.2.170.0050.00815.42
7.2.160.0030.00915.33
7.2.150.0080.01016.97
7.2.140.0100.01017.18
7.2.130.0020.01217.08
7.2.120.0060.00817.26
7.2.110.0040.00617.10
7.2.100.0070.00617.18
7.2.90.0030.01017.29
7.2.80.0050.01017.33
7.2.70.0080.00416.88
7.2.60.0070.00917.30
7.2.50.0040.01017.24
7.2.40.0050.00717.07
7.2.30.0020.01117.13
7.2.20.0070.01017.22
7.2.10.0030.01217.28
7.2.00.0040.00817.90
7.1.330.0050.00516.12
7.1.320.0050.00516.03
7.1.310.0070.00716.00
7.1.300.0020.01016.01
7.1.290.0020.01116.22
7.1.280.0050.00816.14
7.1.270.0030.01116.13
7.1.260.0050.00916.14
7.1.250.0080.00315.94
7.1.240.0080.00516.15
7.1.230.0050.00716.03
7.1.220.0050.00816.04
7.1.210.0060.00616.22
7.1.200.0020.00916.01
7.1.190.0060.00516.13
7.1.180.0050.00516.16
7.1.170.0070.00516.11
7.1.160.0050.00716.23
7.1.150.0040.00816.24
7.1.140.0050.00916.09
7.1.130.0060.00816.16
7.1.120.0060.00915.98
7.1.110.0050.00915.94
7.1.100.0000.01216.01
7.1.90.0040.00816.15
7.1.80.0060.00716.22
7.1.70.0060.00516.57
7.1.60.0050.00816.41
7.1.50.0100.00616.49
7.1.40.0050.01016.09
7.1.30.0030.00916.21
7.1.20.0080.00316.05
7.1.10.0050.01116.20
7.1.00.0060.03018.26
7.0.330.0000.01415.74
7.0.320.0050.00515.66
7.0.310.0030.00815.90
7.0.300.0060.00515.75
7.0.290.0070.00215.46
7.0.280.0040.01315.75
7.0.270.0050.00515.57
7.0.260.0050.01015.60
7.0.250.0070.00915.71
7.0.240.0050.00615.75
7.0.230.0060.00715.71
7.0.220.0080.00515.86
7.0.210.0040.01115.54
7.0.200.0040.00916.09
7.0.190.0060.00915.84
7.0.180.0050.00915.65
7.0.170.0060.00615.74
7.0.160.0070.00815.72
7.0.150.0020.00915.69
7.0.140.0070.00915.68
7.0.130.0070.00615.54
7.0.120.0030.00815.70
7.0.110.0020.01015.81
7.0.100.0080.01717.12
7.0.90.0040.01917.29
7.0.80.0110.03217.07
7.0.70.0020.03517.32
7.0.60.0070.03217.28
7.0.50.0100.02517.35
7.0.40.0070.02215.90
7.0.30.0090.02815.94
7.0.20.0110.03116.05
7.0.10.0100.03016.03
7.0.00.0070.03215.98
5.6.400.0060.01014.01
5.6.390.0060.00814.05
5.6.380.0070.00314.34
5.6.370.0000.01214.14
5.6.360.0060.00613.98
5.6.350.0030.00714.19
5.6.340.0060.01114.18
5.6.330.0030.01014.21
5.6.320.0030.00914.24
5.6.310.0130.00014.18
5.6.300.0050.00714.22
5.6.290.0070.00614.09
5.6.280.0060.00414.29
5.6.270.0020.00914.26
5.6.260.0060.00814.29
5.6.250.0060.02216.19
5.6.240.0090.03216.18
5.6.230.0050.03516.21
5.6.220.0070.01816.23
5.6.210.0090.03116.27
5.6.200.0090.03116.35
5.6.190.0020.04016.39
5.6.180.0110.02516.44
5.6.170.0110.03116.36
5.6.160.0070.02216.45
5.6.150.0050.03016.50
5.6.140.0060.03216.42
5.6.130.0110.03016.30
5.6.120.0100.02916.43
5.6.110.0100.03116.47
5.6.100.0070.02416.38
5.6.90.0060.02216.34
5.6.80.0040.03216.20
5.6.70.0090.02816.08
5.6.60.0070.03016.20
5.6.50.0010.02616.18
5.6.40.0060.02916.06
5.6.30.0080.02916.13
5.6.20.0070.03116.15
5.6.10.0060.03316.08
5.6.00.0080.02016.02

preferences:
84.11 ms | 401 KiB | 5 Q