3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Card { private $suit; private $val; public function __construct($val, $suit) { $values = ['J' => 11, 'Q' => 12, 'K' => 13, 'A' => 14]; $suits = array( 'H' => 'Hearts', 'C' => 'Clubs', 'D' => 'Diamonds', 'S' => 'Spades' ); $this->suit = $suits[$suit]; $this->val = $values[$val] ?? $val; } public function getSuit() { return $this->suit; } public function getVal() { return $this->val; } } class Hand { private $cards; private $matches = array(); public function __construct($hand) { $cards = explode(' ', $hand); foreach ($cards as $card) { $val = substr($card, 0, -1); $suit = strtoupper(substr($card, -1)); $this->cards[] = new Card($val, $suit); } $this->values = array_map(function ($card) { return $card->getVal(); }, $this->cards); $this->pairs = $this->toaks = $this->foaks = []; // _T_hree _O_f _A_ _K_ind and _F_our _O_f _A_ _K_ind $this->possibleStraight = true; $this->hands = array_count_values($this->values); if (max($this->hands) > 1) { $this->possibleStraight = false; } foreach($this->hands as $face => $count) { if ($count === 2) { $this->pairs[] = $face; } if ($count === 3) { $this->toaks[] = $face; } if ($count === 4) { $this->foaks[] = $face; } } } public function testMethods() { var_dump($this->getHighCard()); var_dump($this->getPairs()); var_dump($this->getToaks()); var_dump($this->getFoaks()); var_dump($this->isFullHouse()); var_dump($this->isStraight()); } public function getCards() { return $this->cards; } public function getValues() { return $this->values; } public function getHighCard() { return max($this->getValues()); } public function getPairs(){ return $this->pairs; } public function getToaks(){ return $this->toaks; } public function getFoaks() { return $this->foaks; } public function hasAce() { return isset($this->hands['14']); } public function isFullHouse() { return count($this->pairs) == 1 && count($this->toaks) == 1; } public function isStraight(){ if (! $this->possibleStraight) { return false; } // the rest is up to you if ($this->hasAce()) { } } } $h = new Hand('6h 6d 6s 2c 2h'); $h->testMethods(); echo "\n\nSecond hand:\n"; $h = new Hand('6h 7d 8s 9c 10h'); $h->testMethods();

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.0110.00718.27
8.3.50.0100.00918.31
8.3.40.0040.01518.72
8.3.30.0090.00618.65
8.3.20.0070.00021.87
8.3.10.0090.00021.75
8.3.00.0040.00421.73
8.2.180.0160.00625.92
8.2.170.0110.00722.96
8.2.160.0030.01020.44
8.2.150.0030.00524.18
8.2.140.0110.00424.66
8.2.130.0030.00619.82
8.2.120.0040.00426.35
8.2.110.0030.00720.27
8.2.100.0040.00818.00
8.2.90.0080.00017.91
8.2.80.0050.00317.97
8.2.70.0040.00417.93
8.2.60.0080.00018.34
8.2.50.0050.00318.10
8.2.40.0040.00419.48
8.2.30.0000.00820.55
8.2.20.0000.00918.18
8.2.10.0020.00519.59
8.2.00.0040.00418.18
8.1.280.0120.00325.92
8.1.270.0030.00720.39
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0040.00422.26
8.1.230.0040.00822.75
8.1.220.0030.00517.91
8.1.210.0090.00318.79
8.1.200.0030.00917.48
8.1.190.0090.00017.36
8.1.180.0090.00018.10
8.1.170.0080.00018.70
8.1.160.0040.00418.93
8.1.150.0040.00418.86
8.1.140.0040.00419.12
8.1.130.0040.00417.53
8.1.120.0040.00417.47
8.1.110.0030.00717.58
8.1.100.0000.00817.56
8.1.90.0050.00317.47
8.1.80.0050.00317.55
8.1.70.0030.00317.54
8.1.60.0030.00617.68
8.1.50.0040.00417.48
8.1.40.0030.00617.55
8.1.30.0030.00617.57
8.1.20.0040.00417.56
8.1.10.0000.00717.63
8.1.00.0040.00417.57
8.0.300.0080.00021.51
8.0.290.0040.00416.88
8.0.280.0030.00318.43
8.0.270.0000.00917.38
8.0.260.0070.00016.89
8.0.250.0000.00717.03
8.0.240.0030.00616.91
8.0.230.0050.00217.02
8.0.220.0050.00216.98
8.0.210.0080.00016.82
8.0.200.0000.00717.06
8.0.190.0000.00816.92
8.0.180.0000.00716.91
8.0.170.0000.00916.95
8.0.160.0080.00316.96
8.0.150.0040.00416.80
8.0.140.0030.00616.95
8.0.130.0000.00513.32
8.0.120.0000.00816.83
8.0.110.0040.00416.91
8.0.100.0000.00816.85
8.0.90.0000.00816.80
8.0.80.0130.00916.98
8.0.70.0000.00716.97
8.0.60.0020.00516.83
8.0.50.0000.00716.95
8.0.30.0070.01417.01
8.0.20.0080.01217.02
8.0.10.0000.00717.19
8.0.00.0120.01116.85
7.4.330.0050.00015.55
7.4.320.0030.00316.55
7.4.300.0030.00316.48
7.4.290.0040.00416.43
7.4.280.0040.00416.58
7.4.270.0000.00716.64
7.4.260.0000.00816.54
7.4.250.0040.00416.52
7.4.240.0000.00716.58
7.4.230.0000.00716.74
7.4.220.0030.00616.75
7.4.210.0100.00416.58
7.4.200.0040.00416.47
7.4.160.0160.00516.41
7.4.130.0060.01216.64
7.4.120.0090.00916.63
7.4.110.0100.00616.51
7.4.100.0040.01616.70
7.4.90.0070.01016.54
7.4.80.0130.01019.39
7.4.70.0060.01516.61
7.4.60.0110.00516.47
7.4.50.0100.00616.30
7.4.40.0080.00816.61
7.4.00.0080.00914.96
7.3.330.0030.00313.24
7.3.320.0030.00313.45
7.3.310.0070.00016.43
7.3.300.0040.00416.42
7.3.290.0000.00716.42
7.3.280.0040.01216.29
7.3.260.0080.01116.60
7.3.240.0080.01116.51
7.3.230.0120.00616.48
7.3.210.0160.00516.62
7.3.200.0060.01016.27
7.3.190.0090.00916.56
7.3.180.0050.01116.66
7.3.170.0070.01016.50
7.3.160.0150.00416.34
7.3.120.0070.01114.96
7.3.110.0100.00714.77
7.3.100.0030.01114.80
7.3.90.0100.00614.78
7.3.80.0050.00814.79
7.3.70.0090.00514.93
7.3.60.0090.00514.77
7.3.50.0060.00814.82
7.3.40.0080.00514.89
7.3.30.0090.00514.77
7.3.20.0040.01316.13
7.3.10.0060.00916.14
7.3.00.0100.00516.23
7.2.330.0080.01216.73
7.2.320.0130.01016.69
7.2.310.0140.00716.48
7.2.300.0090.00916.78
7.2.290.0060.01016.74
7.2.250.0070.01015.02
7.2.240.0120.00615.19
7.2.230.0020.01315.19
7.2.220.0050.01115.10
7.2.210.0050.01115.09
7.2.200.0070.00515.08
7.2.190.0060.00814.96
7.2.180.0090.00715.08
7.2.170.0070.00814.97
7.2.160.0070.00814.89
7.2.150.0060.01015.98
7.2.140.0060.00815.92
7.2.130.0090.00815.87
7.2.120.0110.00616.12
7.2.110.0140.00816.01
7.2.100.0120.00515.92
7.2.90.0100.01216.03
7.2.80.0070.01215.86
7.2.70.0060.00816.06
7.2.60.0050.00915.92
7.2.50.0510.00815.85
7.2.40.0100.01015.86
7.2.30.0120.00916.10
7.2.20.0040.00915.96
7.2.10.0110.01115.96
7.2.00.0080.01216.06
7.1.330.0040.01115.67
7.1.320.0050.00815.69
7.1.310.0090.00515.63
7.1.300.0040.01015.84
7.1.290.0070.00615.70
7.1.280.0090.00615.37
7.1.270.0110.00915.29
7.1.260.0060.01015.38
7.1.250.0090.00714.92

preferences:
71.72 ms | 401 KiB | 5 Q