3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ICupboard { public function getNextCup(): Cup; public function haveCups(): bool; } class InfiniteCupBoard implements ICupboard { public function getNextCup(): Cup { return Cup::createEmpty(); } public function haveCups(): bool { return true; } } interface ITap { public function getWater(): Liquid; } class InfiniteTap implements ITap { private int $waterVolumePerReuqest; public function __construct(int $waterVolumePerReuqest) { $this->waterVolumePerReuqest = $waterVolumePerReuqest; } public function getWater(): Liquid { return Liquid::createVolume($this->waterVolumePerReuqest); } } class Cup { private Liquid $liquid; private int $volume; private function __construct(Liquid $liquid, int $volume = 300) { $this->liquid = $liquid; $this->volume = $volume; } public static function createEmpty(): self { return new self(Liquid::createEmpty()); } public function fill(Liquid $liquid): void { if (false === $this->canAddLiquid($liquid)) { throw new DomainException( sprintf( 'Cannot hold liquid volume. Expected volume: %s. Current volume: %s. Provided volume: %s.', $this->volume, $this->liquid->getVolume(), $liquid->getVolume() ) ); } $this->liquid = $this->liquid->add($liquid); } public function canAddLiquid(Liquid $liquid): bool { return $this->volume >= $this->liquid->getVolume() + $liquid->getVolume(); } } class Liquid { private int $volume; private function __construct(int $volume) { $this->volume = $volume; } public static function createEmpty(): self { return new self(0); } public static function createVolume(int $volume): self { return new self($volume); } public function add(Liquid $liquid): self { return new self($this->volume + $liquid->volume); } public function getVolume(): int { return $this->volume; } } class FillCupsWithWater { private ITap $tap; private ICupboard $cupboard; public function __construct(ITap $tap, ICupboard $cupboard) { $this->tap = $tap; $this->cupboard = $cupboard; } public function __invoke(int $cupsToFillCount): array { $filledCups = []; while($this->cupboard->haveCups() && $cupsToFillCount) { $cup = $this->cupboard->getNextCup(); $water = $this->tap->getWater(); while($cup->canAddLiquid($water)) { $cup->fill($water); } $filledCups[] = $cup; $cupsToFillCount--; } return $filledCups; } } $fillCupsWithWater = new FillCupsWithWater(new InfiniteTap(14), new InfiniteCupBoard); print_r($fillCupsWithWater(4));

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.00716.75
8.3.50.0070.01520.07
8.3.40.0120.00423.61
8.3.30.0110.00418.71
8.3.20.0080.00024.18
8.3.10.0040.00424.66
8.3.00.0030.00626.16
8.2.180.0130.00725.92
8.2.170.0110.00418.91
8.2.160.0070.00722.96
8.2.150.0080.00025.66
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0040.00426.16
8.2.110.0030.00620.47
8.2.100.0120.00019.45
8.2.90.0070.00317.75
8.2.80.0000.00818.78
8.2.70.0050.00317.63
8.2.60.0050.00317.63
8.2.50.0000.00817.98
8.2.40.0040.00417.79
8.2.30.0080.00017.79
8.2.20.0000.00720.34
8.2.10.0040.00417.80
8.2.00.0050.00219.40
8.1.280.0060.00925.92
8.1.270.0000.00723.99
8.1.260.0000.00826.35
8.1.250.0000.00828.09
8.1.240.0070.00323.96
8.1.230.0080.00317.83
8.1.220.0000.00817.74
8.1.210.0000.00818.77
8.1.200.0000.01017.48
8.1.190.0000.00817.23
8.1.180.0040.00418.10
8.1.170.0000.00717.63
8.1.160.0000.00718.89
8.1.150.0030.00518.64
8.1.140.0000.00717.54
8.1.130.0040.00417.48
8.1.120.0030.00417.50
8.1.110.0000.00717.46
8.1.100.0040.00417.50
8.1.90.0070.00317.43
8.1.80.0070.00017.47
8.1.70.0040.00417.53
8.1.60.0040.00417.51
8.1.50.0030.00617.48
8.1.40.0040.00417.52
8.1.30.0000.00817.70
8.1.20.0030.00617.70
8.1.10.0080.00017.55
8.1.00.0040.01117.44
8.0.300.0000.00818.77
8.0.290.0050.00316.75
8.0.280.0040.00418.36
8.0.270.0040.00416.88
8.0.260.0000.00716.99
8.0.250.0000.00717.06
8.0.240.0030.00317.02
8.0.230.0020.00516.97
8.0.220.0000.00817.05
8.0.210.0040.00416.87
8.0.200.0070.00017.07
8.0.190.0040.00417.12
8.0.180.0030.00717.01
8.0.170.0040.00416.89
8.0.160.0030.00617.02
8.0.150.0040.00316.95
8.0.140.0040.00416.86
8.0.130.0000.01316.86
8.0.120.0150.00416.87
8.0.110.0180.00016.98
8.0.100.0130.00516.76
8.0.90.0090.00916.92
8.0.80.0150.00416.94
8.0.70.0200.00017.01
8.0.60.0130.00716.93
8.0.50.0230.00016.91
8.0.30.0140.00416.91
8.0.20.0120.00616.98
8.0.10.0190.00017.06
8.0.00.0080.00517.08
7.4.330.0000.00515.55
7.4.320.0060.00016.66
7.4.300.0070.00016.56
7.4.290.0030.00316.61
7.4.280.0030.00616.64
7.4.270.0040.00916.50
7.4.260.0220.00016.63
7.4.250.0170.00516.62
7.4.240.0130.00916.38
7.4.230.0170.00616.63
7.4.220.0190.00016.55
7.4.210.0140.00316.45
7.4.200.0140.00516.62
7.4.190.0140.00616.57
7.4.180.0130.00616.52
7.4.160.0130.00716.43
7.4.150.0200.00016.43
7.4.140.0150.00416.38
7.4.130.0110.00816.54
7.4.120.0100.01016.55
7.4.110.0170.00416.50
7.4.100.0160.00416.65
7.4.90.0160.00416.40
7.4.80.0150.00216.41
7.4.70.0120.00216.50
7.4.60.0070.00716.58
7.4.50.0180.00016.43
7.4.40.0160.00316.38
7.4.30.0100.00516.49
7.4.20.0110.00716.50
7.4.10.0190.00016.55
7.4.00.0050.01016.40
7.3.330.0080.00416.12
7.3.320.0050.01016.11
7.3.310.0140.00316.17
7.3.300.0130.00015.99
7.3.290.0120.00315.95
7.3.280.0160.00316.22
7.3.270.0070.00716.12
7.3.260.0150.00016.23
7.3.250.0080.00816.13
7.3.240.0140.00016.11
7.3.230.0180.00015.95
7.3.220.0210.00016.13
7.3.210.0110.00216.02
7.3.200.0090.00315.96
7.3.190.0180.00015.89
7.3.180.0210.00015.93
7.3.170.0150.00316.02
7.3.160.0050.00515.93
7.3.150.0060.00615.89
7.3.140.0160.00015.86
7.3.130.0110.00416.10

preferences:
61.2 ms | 400 KiB | 5 Q