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.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.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.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:
56.78 ms | 406 KiB | 5 Q