3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Card { private $suit; private $val; public function __construct($val, $suit) { $values = array( '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, '10' => 10, '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]; } public function getSuit() { return $this->suit; } public function getVal() { return $this->val; } } class Hand { private $cards; private $matches; 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->isFlush(); $this->isStraight(); $this->isFourKind(); $this->isThreeKind(); $this->isTwoPair(); $this->isOnePair(); $this->isHighCard(); } public function getCards(){ return $this->cards; } public function getValues(){ foreach($this->cards as $card){ $output[] = $card->getVal(); } return $output; } public function getSuits(){ foreach($this->cards as $card){ $output[] = $card->getSuit(); } return $output; } public function isHighCard(){ $output = max($this->getValues()); return $output; } public function isPair(){ $this->matches = array(); foreach(array_count_values($this->getValues()) as $value => $count){ if ($count == 2 && count($this->matches) < 2) { $this->matches[] = $value; } } } public function isOnePair(){ $this->isPair(); if (count($this->matches) == 1) { echo "One pair"; } } public function isTwoPair(){ $this->isPair(); if (count($this->matches) == 2) { echo "Two pair"; } } public function isThreeKind(){ $count = max(array_count_values($this->getValues())); if($count == 3){ echo "Three of a kind"; } } public function isFourKind(){ $count = max(array_count_values($this->getValues())); if($count == 4){ echo "Four of a kind"; } } public function isStraight(){ $min = min($this->getValues()); } public function isFlush(){ foreach (array_count_values($this->getSuits()) as $value => $count){ if ($count == 5) { echo "Flush"; } } } public function isStraightFlush(){ } } $h = new Hand('Kh Kc 3s 3h 2d'); // var_dump($x);

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.0040.01518.30
8.3.50.0120.00717.38
8.3.40.0110.00818.79
8.3.30.0150.00018.67
8.3.20.0000.00721.75
8.3.10.0080.00021.93
8.3.00.0040.00421.78
8.2.180.0170.00016.50
8.2.170.0040.01122.96
8.2.160.0130.00320.52
8.2.150.0050.00324.18
8.2.140.0000.00824.66
8.2.130.0000.00819.95
8.2.120.0040.00426.35
8.2.110.0060.00319.21
8.2.100.0060.00617.91
8.2.90.0040.00417.63
8.2.80.0040.00418.04
8.2.70.0030.00518.05
8.2.60.0080.00018.16
8.2.50.0090.00018.10
8.2.40.0070.00019.38
8.2.30.0040.00420.43
8.2.20.0070.00418.21
8.2.10.0070.00019.45
8.2.00.0080.00018.20
8.1.280.0040.01225.92
8.1.270.0030.00520.31
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0070.00323.92
8.1.230.0140.00320.80
8.1.220.0080.00317.74
8.1.210.0030.00718.77
8.1.200.0000.01017.35
8.1.190.0060.00317.35
8.1.180.0040.00418.10
8.1.170.0040.00418.50
8.1.160.0000.00718.80
8.1.150.0060.00318.99
8.1.140.0040.00419.09
8.1.130.0000.00720.15
8.1.120.0000.00717.48
8.1.110.0000.00817.50
8.1.100.0000.00717.50
8.1.90.0040.00417.39
8.1.80.0070.00017.42
8.1.70.0000.00717.40
8.1.60.0000.00817.50
8.1.50.0000.00817.44
8.1.40.0000.00817.52
8.1.30.0080.00317.64
8.1.20.0040.00417.71
8.1.10.0040.00417.60
8.1.00.0080.00017.50
8.0.300.0070.00019.83
8.0.290.0050.00216.63
8.0.280.0030.00318.47
8.0.270.0080.00017.20
8.0.260.0030.00318.39
8.0.250.0030.00316.98
8.0.240.0040.00416.88
8.0.230.0030.00316.87
8.0.220.0030.00316.92
8.0.210.0030.00516.93
8.0.200.0030.00616.97
8.0.190.0080.00016.98
8.0.180.0040.00416.83
8.0.170.0000.00916.98
8.0.160.0060.00616.86
8.0.150.0030.00816.88
8.0.140.0030.00616.89
8.0.130.0000.00613.39
8.0.120.0040.00416.92
8.0.110.0000.00716.86
8.0.100.0000.00716.99
8.0.90.0040.00416.96
8.0.80.0060.00816.80
8.0.70.0070.00016.83
8.0.60.0020.00516.80
8.0.50.0000.00716.88
8.0.30.0100.00817.02
8.0.20.0150.00717.13
8.0.10.0070.00017.11
8.0.00.0110.00916.92
7.4.330.0000.00516.68
7.4.320.0000.00616.55
7.4.300.0000.00816.63
7.4.290.0000.00716.55
7.4.280.0040.00416.64
7.4.270.0040.00716.64
7.4.260.0000.00816.59
7.4.250.0070.00016.50
7.4.240.0040.00416.52
7.4.230.0000.00716.71
7.4.220.0030.00516.51
7.4.210.0090.00716.63
7.4.200.0000.00716.73
7.4.160.0090.00916.52
7.4.140.0070.01017.86
7.4.130.0070.01116.64
7.4.120.0070.01016.50
7.4.110.0030.01416.50
7.4.100.0130.00716.66
7.4.90.0100.00716.55
7.4.80.0140.00719.39
7.4.70.0040.01316.42
7.4.60.0030.01316.49
7.4.50.0030.01216.46
7.4.40.0110.00716.43
7.4.00.0090.00514.91
7.3.330.0030.00313.12
7.3.320.0030.00313.29
7.3.310.0030.00316.37
7.3.300.0000.00616.30
7.3.290.0000.00716.35
7.3.280.0070.00716.31
7.3.260.0100.00916.56
7.3.240.0130.00716.43
7.3.230.0050.01316.63
7.3.210.0110.00616.45
7.3.200.0070.01116.36
7.3.190.0090.00916.27
7.3.180.0090.01316.47
7.3.170.0090.01316.28
7.3.160.0100.01016.51
7.3.120.0100.00714.96
7.3.110.0100.00714.80
7.3.100.0070.00714.93
7.3.90.0060.00314.84
7.3.80.0060.00914.65
7.3.70.0000.00914.80
7.3.60.0030.01214.91
7.3.50.0110.00714.82
7.3.40.0080.00614.95
7.3.30.0060.00614.85
7.3.20.0090.01016.07
7.3.10.0070.01016.18
7.3.00.0110.00915.97
7.2.330.0100.01016.89
7.2.320.0040.01816.62
7.2.310.0030.01516.92
7.2.300.0130.00716.74
7.2.290.0060.01516.75
7.2.250.0040.01515.05
7.2.240.0100.01014.99
7.2.230.0030.01015.06
7.2.220.0110.00415.14
7.2.210.0090.00915.21
7.2.200.0040.01115.24
7.2.190.0090.00915.20
7.2.180.0080.00815.01
7.2.170.0070.00815.16
7.2.160.0090.00615.07
7.2.150.0430.00916.11
7.2.140.0110.00616.07
7.2.130.0100.00516.04
7.2.120.0090.00616.09
7.2.110.0110.00916.09
7.2.100.0180.00316.02
7.2.90.0110.01016.04
7.2.80.0090.01116.05
7.2.70.0100.00516.08
7.2.60.0080.01116.17
7.2.50.0100.01116.04
7.2.40.0160.00915.96
7.2.30.0130.00716.12
7.2.20.0160.00516.11
7.2.10.0110.00915.99
7.2.00.0080.00616.20
7.1.330.0110.00415.81
7.1.320.0040.01115.58
7.1.310.0070.00716.05
7.1.300.0030.01215.81
7.1.290.0060.00915.77
7.1.280.0060.00715.27
7.1.270.0100.00815.04
7.1.260.0090.00915.20
7.1.250.0120.00714.84

preferences:
89.22 ms | 401 KiB | 5 Q