3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare (strict_types=1); final class Position { private $row; private $column; public function __construct(int $row, int $column) { $this->row = $row; $this->column = $column; } public function is(Position $position) : bool { return $this->row === $position->row && $this->column === $position->column; } } final class Tile { private $position; private $clicked; public function __construct(Position $position) { $this->position = $position; $this->clicked = false; } public static function clicked(Position $position) : self { $tile = new self($position); $tile->clicked = true; return $tile; } public function position() : Position { return $this->position; } public function click() : self { if ($this->isClicked()) { throw new \RuntimeException('Tile can\'t be clicked twice'); } var_dump(self::clicked($this->position)); return self::clicked($this->position); } public function isClicked() : bool { return $this->clicked; } } final class Tiles { /** * @var Tile[] */ private $tiles; public function __construct(Tile ...$tiles) { $this->tiles = $tiles; } public function count() : int { return \count($this->tiles); } public function hasMoreThan(Position $position, int $expectedLimit) : bool { return $this->find( function(Tile $tile) use ($position) { return $tile->position()->is($position); } )->count() > $expectedLimit; } public function each(callable $callback) : void { array_map($callback, $this->tiles); } public function find(callable $callback) : Tiles { return new Tiles(...array_filter( $this->tiles, $callback )); } public function map(callable $callback) : array { return array_map($callback, $this->tiles); } public function has(Position $position) : bool { return (bool) $this->find( function(Tile $tile) use ($position) { return $tile->position()->is($position); } )->count(); } public function clickedCount() : int { return (int) array_reduce( $this->tiles, function(int $clicked, Tile $nextTile) { return $nextTile->isClicked() ? $clicked + 1 : $clicked; }, 0 ); } } final class Board { /** * @var Tiles */ private $tiles; public function __construct(Tiles $tiles) { $tiles->each(function(Tile $tile) use ($tiles) { if ($tiles->hasMoreThan($tile->position(), 1)) { throw new \RuntimeException('Board can have only tile at each position'); } }); $this->tiles = $tiles; } public function click(Position $position) : void { if (!$this->tiles->has($position)) { throw new \RuntimeException('Tile does not exists'); } $this->tiles = new Tiles(...$this->tiles->map(function(Tile $tile) use ($position) { return $tile->position()->is($position) ? $tile->click() : $tile; })); } public function score() : int { return $this->tiles->clickedCount(); } } $board = new Board(new Tiles( new Tile(new Position(0, 0)), new Tile(new Position(0, 1)), new Tile(new Position(0, 2)), new Tile(new Position(0, 3)), new Tile(new Position(0, 4)), new Tile(new Position(0, 5)) )); $board->click(new Position(0, 0)); $board->click(new Position(0, 1)); $board->click(new Position(0, 2)); $board->click(new Position(0, 3)); $board->click(new Position(0, 4)); $board->click(new Position(0, 5)); print "\n"; Board::clicked(new Position(0, 0)); var_dump($board->score());

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.0080.00818.31
8.3.50.0120.00618.45
8.3.40.0150.00718.96
8.3.30.0100.00618.84
8.3.20.0080.00019.28
8.3.10.0050.00319.46
8.3.00.0040.00423.68
8.2.180.0060.00918.54
8.2.170.0090.00922.96
8.2.160.0060.01320.51
8.2.150.0080.00024.18
8.2.140.0050.00324.66
8.2.130.0080.00019.77
8.2.120.0040.00426.35
8.2.110.0030.00722.25
8.2.100.0040.00817.86
8.2.90.0000.00819.47
8.2.80.0040.00418.05
8.2.70.0000.00818.05
8.2.60.0030.00618.29
8.2.50.0040.00818.10
8.2.40.0060.00319.47
8.2.30.0040.00419.51
8.2.20.0000.00918.13
8.2.10.0030.00518.14
8.2.00.0040.00419.51
8.1.280.0100.00725.92
8.1.270.0030.00522.02
8.1.260.0040.00426.35
8.1.250.0030.00528.09
8.1.240.0030.00623.97
8.1.230.0080.00417.89
8.1.220.0030.00617.79
8.1.210.0000.00818.77
8.1.200.0030.00617.48
8.1.190.0000.00817.35
8.1.180.0040.00418.10
8.1.170.0040.00418.66
8.1.160.0030.00519.02
8.1.150.0000.00918.98
8.1.140.0000.00717.71
8.1.130.0040.00419.13
8.1.120.0070.00017.51
8.1.110.0030.00517.55
8.1.100.0040.00417.57
8.1.90.0040.00417.56
8.1.80.0000.00817.56
8.1.70.0000.00717.54
8.1.60.0060.00317.71
8.1.50.0060.00317.61
8.1.40.0000.00817.50
8.1.30.0090.00017.70
8.1.20.0000.00817.64
8.1.10.0040.00417.63
8.1.00.0080.00017.56
8.0.300.0040.00418.77
8.0.290.0080.00016.88
8.0.280.0030.00518.54
8.0.270.0040.00417.26
8.0.260.0050.00217.37
8.0.250.0000.00917.01
8.0.240.0000.00816.95
8.0.230.0000.00817.06
8.0.220.0070.00316.92
8.0.210.0000.00717.09
8.0.200.0040.00417.06
8.0.190.0040.00417.02
8.0.180.0000.00817.10
8.0.170.0050.00517.03
8.0.160.0040.00416.93
8.0.150.0000.01016.99
8.0.140.0000.00717.02
8.0.130.0030.00713.48
8.0.120.0030.00517.01
8.0.110.0040.00416.99
8.0.100.0080.00317.14
8.0.90.0000.00816.95
8.0.80.0100.01217.09
8.0.70.0030.00616.91
8.0.60.0040.00416.91
8.0.50.0030.00516.91
8.0.30.0090.01117.22
8.0.20.0140.00617.40
8.0.10.0000.00917.05
8.0.00.0190.02716.73
7.4.330.0050.00015.55
7.4.320.0000.00616.55
7.4.300.0070.00016.69
7.4.290.0040.00416.60
7.4.280.0040.00416.65
7.4.270.0030.00516.67
7.4.260.0000.00716.48
7.4.250.0040.00416.59
7.4.240.0050.00316.74
7.4.230.0000.00716.70
7.4.220.0080.00016.67
7.4.210.0050.01016.65
7.4.200.0040.00416.49
7.4.160.0110.00616.62
7.4.140.0090.01217.86
7.4.130.0130.01016.71
7.4.120.0120.00916.64
7.4.110.0030.01616.69
7.4.100.0040.01416.64
7.4.90.0070.01016.65
7.4.80.0100.01019.39
7.4.70.0030.01716.48
7.4.60.0090.00816.69
7.4.50.0060.00916.47
7.4.40.0140.01316.67
7.4.10.0100.01015.02
7.4.00.0030.01715.26
7.3.330.0000.00513.42
7.3.320.0030.00313.31
7.3.310.0040.00416.34
7.3.300.0040.00416.44
7.3.290.0000.00816.41
7.3.280.0060.01016.46
7.3.260.0120.00716.47
7.3.240.0080.01116.53
7.3.230.0160.00416.69
7.3.210.0110.00716.46
7.3.200.0070.01116.44
7.3.190.0030.01516.37
7.3.180.0070.01016.54
7.3.170.0070.01116.69
7.3.160.0130.00416.52
7.3.130.0090.01215.09
7.3.120.0100.01015.16
7.3.110.0040.01115.00
7.3.100.0060.00914.86
7.3.90.0040.01415.13
7.3.80.0090.00614.82
7.3.70.0040.00915.01
7.3.60.0070.01114.84
7.3.50.0070.00614.57
7.3.40.0000.01014.99
7.3.30.0120.00314.99
7.3.20.0130.00716.71
7.3.10.0040.01116.81
7.3.00.0060.01016.46
7.2.330.0060.01316.64
7.2.320.0050.01416.93
7.2.310.0130.01316.76
7.2.300.0040.01416.80
7.2.290.0070.01616.84
7.2.260.0120.00415.10
7.2.250.0060.01315.18
7.2.240.0000.01815.29
7.2.230.0030.01014.97
7.2.220.0120.00814.75
7.2.210.0060.00915.37
7.2.200.0040.01215.38
7.2.190.0040.01515.14
7.2.180.0110.00315.11
7.2.170.0060.00614.89
7.2.160.0090.00315.00
7.2.150.0030.01717.04
7.2.140.0030.01016.74
7.2.130.0120.00616.84
7.2.120.0000.01217.18
7.2.110.0090.00916.91
7.2.100.0070.00717.04
7.2.90.0090.00616.88
7.2.80.0060.00616.93
7.2.70.0060.00916.96
7.2.60.0060.01216.70
7.2.50.0060.01216.96
7.2.40.0110.00417.13
7.2.30.0040.00916.94
7.2.20.0070.00416.82
7.2.10.0030.01317.18
7.2.00.0000.01116.96
7.1.330.0030.01315.94
7.1.320.0110.00716.02
7.1.310.0040.01115.71
7.1.300.0060.00616.01
7.1.290.0080.00415.82
7.1.280.0040.01115.80
7.1.270.0040.01115.76
7.1.260.0080.00815.87
7.1.250.0100.00715.83
7.1.240.0100.00715.62
7.1.230.0070.00715.96
7.1.220.0060.00615.89
7.1.210.0090.00315.81
7.1.200.0040.01115.76
7.1.190.0040.00815.63
7.1.180.0070.00715.91
7.1.170.0080.00615.83
7.1.160.0060.00615.63
7.1.150.0080.00815.88
7.1.140.0060.00915.81
7.1.130.0090.00615.62
7.1.120.0070.00415.95
7.1.110.0030.01315.50
7.1.100.0030.00615.73
7.1.90.0070.00715.86
7.1.80.0070.00415.84
7.1.70.0060.00315.89
7.1.60.0000.01416.02
7.1.50.0060.01015.93
7.1.40.0070.00315.68
7.1.30.0030.01015.80
7.1.20.0040.01215.78
7.1.10.0090.00615.79
7.1.00.0060.00615.96
7.0.330.0070.01015.34
7.0.320.0030.01115.22
7.0.310.0000.01415.43
7.0.300.0090.00615.38
7.0.290.0030.00615.34
7.0.280.0040.00415.13
7.0.270.0100.00315.43
7.0.260.0030.01015.25
7.0.250.0050.00415.54
7.0.240.0060.00915.40
7.0.230.0060.00815.37
7.0.220.0040.00715.54
7.0.210.0050.00515.44
7.0.200.0100.00715.34
7.0.190.0140.00315.23
7.0.180.0000.01215.44
7.0.170.0000.01115.25
7.0.160.0000.01515.55
7.0.150.0070.00715.52
7.0.140.0040.00815.46
7.0.130.0000.01115.35
7.0.120.0000.01315.53
7.0.110.0000.01015.27
7.0.100.0070.00415.23
7.0.90.0000.01015.51
7.0.80.0040.00815.43
7.0.70.0030.00615.46
7.0.60.0100.00315.54
7.0.50.0110.00015.61
7.0.40.0030.01013.41
7.0.30.0140.00013.46
7.0.20.0090.00613.36
7.0.10.0080.00413.28
7.0.00.0060.00613.53
5.6.400.0090.00313.96
5.6.390.0110.00414.24
5.6.380.0080.00814.30
5.6.370.0110.00414.34
5.6.360.0080.00414.29
5.6.350.0040.00813.80
5.6.340.0030.01014.19
5.6.330.0040.01114.03
5.6.320.0030.01014.07
5.6.310.0110.00414.28
5.6.300.0030.01014.02
5.6.290.0040.00714.37
5.6.280.0030.01014.38
5.6.270.0120.00313.97
5.6.260.0070.00714.38
5.6.250.0070.00714.14
5.6.240.0000.00914.40
5.6.230.0030.00714.27
5.6.220.0030.00514.12
5.6.210.0040.00814.01
5.6.200.0090.00613.89
5.6.190.0030.01213.96
5.6.180.0030.00614.14
5.6.170.0090.00014.04
5.6.160.0000.01214.08
5.6.150.0040.01114.11
5.6.140.0000.00914.04
5.6.130.0000.01213.86
5.6.120.0070.00714.17
5.6.110.0030.01314.43
5.6.100.0030.01314.19
5.6.90.0030.00513.86
5.6.80.0120.00314.18
5.6.70.0000.01414.21
5.6.60.0030.01413.88
5.6.50.0060.00914.12
5.6.40.0030.00714.05
5.6.30.0040.00414.20
5.6.20.0040.00714.13
5.6.10.0110.00413.89
5.6.00.0030.00613.95

preferences:
54.5 ms | 400 KiB | 5 Q