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 = 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->isPair(); $this->isHighCard(); $this->isKind(); $this->isStraight(); } public function getCards(){ return $this->cards; } public function getValues(){ foreach($this->cards as $card){ $output[] = $card->getVal(); } return $output; } public function isHighCard(){ $output = max($this->getValues()); return $output; } public function isPair(){ foreach(array_count_values($this->getValues()) as $value => $count){ if ($count == 2 && count($this->matches) < 2) { $this->matches[] = $value; } } if (count($this->matches) == 1) { echo "One pair"; } if (count($this->matches) == 2) { echo "Two pair"; } } public function isKind(){ $count = max(array_count_values($this->getValues())); if($count == 3){ echo "Three of a kind"; } if($count == 4){ echo "Four of a kind"; } } public function isStraight(){ $cards = $this->getValues(); $previous = null; foreach($cards as $card){ if ($previous !== null && $card == $previous + 1){ echo "Straight"; } $previous = $card; } } } $h = new Hand('9s 9h 9d 10s 8c'); // 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.40.0130.00318.83
8.3.30.0040.01118.71
8.3.20.0000.00821.73
8.3.10.0050.00321.90
8.3.00.0080.00021.85
8.2.170.0150.00622.96
8.2.160.0110.00420.20
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0040.00419.67
8.2.120.0000.00826.35
8.2.110.0060.00319.27
8.2.100.0110.00017.84
8.2.90.0050.00317.63
8.2.80.0030.00618.78
8.2.70.0000.00818.04
8.2.60.0060.00318.21
8.2.50.0040.00418.10
8.2.40.0070.00019.36
8.2.30.0000.00720.52
8.2.20.0060.00318.11
8.2.10.0080.00019.47
8.2.00.0020.00518.10
8.1.270.0030.00620.40
8.1.260.0050.00326.35
8.1.250.0000.00828.09
8.1.240.0040.00723.76
8.1.230.0030.00921.04
8.1.220.0050.00317.78
8.1.210.0040.00418.77
8.1.200.0040.00417.35
8.1.190.0080.00017.23
8.1.180.0040.00418.10
8.1.170.0060.00318.71
8.1.160.0040.00419.01
8.1.150.0000.00818.93
8.1.140.0080.00018.98
8.1.130.0000.00917.44
8.1.120.0000.00717.45
8.1.110.0050.00517.48
8.1.100.0000.00717.53
8.1.90.0070.00017.55
8.1.80.0000.00917.38
8.1.70.0070.00017.55
8.1.60.0000.00817.62
8.1.50.0030.00717.57
8.1.40.0040.00417.60
8.1.30.0080.00017.59
8.1.20.0030.00717.67
8.1.10.0050.00317.49
8.1.00.0070.00017.54
8.0.300.0070.00018.77
8.0.290.0070.00016.88
8.0.280.0000.00718.50
8.0.270.0030.00316.88
8.0.260.0030.00316.95
8.0.250.0000.00716.99
8.0.240.0000.00717.01
8.0.230.0000.00717.02
8.0.220.0030.00316.82
8.0.210.0070.00016.84
8.0.200.0000.00616.91
8.0.190.0000.00916.86
8.0.180.0050.00316.95
8.0.170.0030.00616.96
8.0.160.0060.00316.97
8.0.150.0050.00216.93
8.0.140.0040.00416.91
8.0.130.0060.00013.41
8.0.120.0040.00416.96
8.0.110.0040.00716.89
8.0.100.0000.00816.90
8.0.90.0050.00216.98
8.0.80.0040.01116.91
8.0.70.0000.00817.00
8.0.60.0040.00416.74
8.0.50.0000.00716.81
8.0.30.0120.00717.00
8.0.20.0130.01017.09
8.0.10.0000.00816.93
8.0.00.0120.00816.82
7.4.330.0050.00016.75
7.4.320.0000.00616.55
7.4.300.0030.00316.65
7.4.290.0030.00316.64
7.4.280.0080.00016.55
7.4.270.0030.00316.55
7.4.260.0040.00416.39
7.4.250.0000.00716.61
7.4.240.0070.00016.46
7.4.230.0030.00316.74
7.4.220.0030.00616.75
7.4.210.0080.01016.67
7.4.200.0050.00216.45
7.4.140.0140.01117.86
7.4.130.0100.01016.79
7.4.120.0050.01516.58
7.4.110.0060.01316.46
7.4.100.0030.01616.59
7.4.90.0060.01116.57
7.4.80.0090.00919.39
7.4.70.0140.00416.58
7.4.60.0100.00716.52
7.4.50.0070.01116.57
7.4.40.0080.00916.40
7.4.00.0040.01415.17
7.3.330.0000.00613.42
7.3.320.0060.00013.35
7.3.310.0060.00016.40
7.3.300.0070.00016.33
7.3.290.0000.00716.34
7.3.280.0050.01316.32
7.3.260.0110.01216.56
7.3.240.0110.01116.61
7.3.230.0110.00716.64
7.3.210.0140.00316.30
7.3.200.0100.00716.54
7.3.190.0070.01116.27
7.3.180.0130.01016.27
7.3.170.0120.00416.42
7.3.160.0080.01116.60
7.3.40.0040.00614.82
7.3.30.0090.00714.65
7.3.20.0150.00716.49
7.3.10.0030.01016.56
7.3.00.0100.00616.71
7.2.330.0150.00316.74
7.2.320.0060.01216.91
7.2.310.0110.00716.49
7.2.300.0070.01016.79
7.2.290.0120.01216.84
7.2.170.0050.00814.99
7.2.160.0080.01415.04
7.2.150.0050.01416.82
7.2.140.0080.00816.92
7.2.130.0110.00816.67
7.2.120.0110.00516.94
7.2.110.0060.00816.88
7.2.100.0080.00716.89
7.2.90.0080.00817.03
7.2.80.0040.01016.93
7.2.70.0060.00916.94
7.2.60.0060.00916.75
7.2.50.0080.00616.91
7.2.40.0100.00716.90
7.2.30.0070.01016.85
7.2.20.0070.00716.95
7.2.10.0080.00616.95
7.2.00.0100.01016.93
7.1.280.0110.00515.92
7.1.270.0090.00415.80
7.1.260.0100.00515.72
7.1.250.0030.01015.66

preferences:
61.88 ms | 400 KiB | 5 Q