3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Matrix { private int $rows; private int $columns; private array $values; public function __construct(int $rows, int $columns) { $this->rows = $rows; $this->columns = $columns; } public function rows(): int { return $this->rows; } public function columns() : int { return $this->columns; } } class MatrixFactory { public function create(int $rows, int $columns) : Matrix{ return new Matrix($rows, $columns); } } interface MatrixCommand { public function execute(Matrix $matrix): Response; public function title() :string; } class TransposeMatrixCommand implements MatrixCommand { public const TITLE = 'Pomnóż macierze wejściowe'; public function title() : string { return self::TITLE; } public function execute(Matrix $matrix):Response { return new Response(); } } class MultiplicationMatrixCommand implements MatrixCommand { public const TITLE = 'Pomnóż macierze wejściowe'; public function title() : string { return self::TITLE; } public function execute(Matrix $matrix):Response { return new Response(); } } class Response { } class RegistryMatrixCommand { private array $registry; public function __construct(iterable $commands) { $this->addCommands($commands); } public function addCommand(string $command) { if(false === class_exists($command)) { throw new Exception('Class not exists'); } $this->registry[$command] = new $command; } public function addCommands(iterable $commands) { foreach($commands as $command) { $this->addCommand($command); } } public function get(string $action) : MatrixCommand { if(false === array_key_exists($action, $this->registry)) { throw new Exception('Not found command!'); } return $this->registry[$action]; } public function list() : iterable { return $this->registry; } } class MenuRenderer { private array $commands; public function render(array $commands) : string { $menu = ''; $counter = 1; foreach($commands as $command) { $counter++; $menu .= sprintf('%d - %s', $counter, $command->title()); } return $menu; } } class MatrixAction { private RegistryMatrixCommand $registry; private MenuRenderer $menuRenderer; public function __construct(RegistryMatrixCommand $registry, MenuRenderer $menuRenderer) { $this->registry = $registry; $this->menuRenderer = $menuRenderer; } public function displayActions(): string { return $this->menuRenderer->render($this->registry->list()); } public function execute(Request $request) : Response { $matrix = (new MatrixFactory())->create( $request->rows(), $request->columns() ); $command = $this->registry->get($request->action()); $response = $command->execute($matrix); return $response; } } class Request { private string $action; private int $rows; private int $columns; public function __construct(string $action, int $rows, int $columns) { $this->action = $action; $this->rows = $rows; $this->columns = $columns; } public function action() :string { return $this->action; } public function rows() : int { return $this->rows; } public function columns(): int { return $this->columns; } } $actions = new ArrayIterator([ MultiplicationMatrixCommand::class, TransposeMatrixCommand::class ]); $registryMatrix = new RegistryMatrixCommand($actions); $menuRenderer = new MenuRenderer(); $matrixAction = new MatrixAction($registryMatrix, $menuRenderer); $request = new Request('TransposeMatrixCommand', 3, 4); echo $matrixAction->displayActions(); // var_dump($matrixAction->execute($request));

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.0070.01416.88
8.3.50.0120.00916.45
8.3.40.0120.00318.79
8.3.30.0070.00718.63
8.3.20.0000.00820.85
8.3.10.0000.00823.69
8.3.00.0000.00721.86
8.2.180.0120.00618.38
8.2.170.0070.00722.96
8.2.160.0100.00322.09
8.2.150.0120.00324.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0090.00026.16
8.2.110.0070.00320.38
8.2.100.0120.00017.97
8.2.90.0040.00417.75
8.2.80.0040.00418.73
8.2.70.0060.00317.61
8.2.60.0080.00017.50
8.2.50.0030.00518.05
8.2.40.0050.00318.28
8.2.30.0000.00719.37
8.2.20.0090.00018.12
8.2.10.0040.00419.48
8.2.00.0030.00519.49
8.1.270.0080.00020.75
8.1.260.0080.00026.35
8.1.250.0030.00528.09
8.1.240.0090.00023.63
8.1.230.0070.00420.88
8.1.220.0040.00418.49
8.1.210.0080.00018.77
8.1.200.0000.00817.48
8.1.190.0030.00617.23
8.1.180.0000.00818.10
8.1.170.0030.00517.62
8.1.160.0000.00718.80
8.1.150.0000.00819.10
8.1.140.0040.00422.46
8.1.130.0000.00720.32
8.1.120.0000.00817.44
8.1.110.0040.00417.48
8.1.100.0040.00417.52
8.1.90.0050.00217.50
8.1.80.0040.00417.37
8.1.70.0070.00017.52
8.1.60.0040.00417.58
8.1.50.0000.00817.57
8.1.40.0060.00317.56
8.1.30.0000.00817.74
8.1.20.0100.00017.70
8.1.10.0040.00417.63
8.1.00.0000.00817.56
8.0.300.0040.00418.77
8.0.290.0050.00317.28
8.0.280.0070.00018.49
8.0.270.0030.00318.15
8.0.260.0000.00720.08
8.0.250.0040.00417.04
8.0.240.0000.00817.04
8.0.230.0040.00416.94
8.0.220.0030.00317.02
8.0.210.0030.00516.99
8.0.200.0000.00617.07
8.0.190.0070.00316.98
8.0.180.0040.00416.91
8.0.170.0070.00417.03
8.0.160.0000.00717.03
8.0.150.0040.00416.87
8.0.140.0000.00816.93
8.0.130.0070.00013.43
8.0.120.0040.00416.98
8.0.110.0070.00017.05
8.0.100.0040.00416.98
8.0.90.0000.00916.88
8.0.80.0060.01017.00
8.0.70.0030.00516.92
8.0.60.0050.00216.88
8.0.50.0040.00416.89
8.0.30.0070.01017.32
8.0.20.0110.00817.16
8.0.10.0000.00717.11
8.0.00.0060.01316.82
7.4.330.0020.00216.71
7.4.320.0000.00616.68
7.4.300.0040.00416.48
7.4.290.0000.00716.63
7.4.280.0030.00716.45
7.4.270.0070.00016.57
7.4.260.0000.00513.41
7.4.250.0000.00716.60
7.4.240.0060.00216.66
7.4.230.0030.00616.36
7.4.220.0050.00216.52
7.4.210.0100.00816.63
7.4.200.0020.00516.70
7.4.130.0060.01316.60
7.4.120.0040.01616.66
7.4.110.0070.01116.60
7.4.100.0210.00316.54
7.4.90.0110.00616.52
7.4.80.0140.00819.39
7.4.70.0150.00816.60
7.4.60.0060.01116.60
7.4.50.0080.00816.43
7.4.40.0160.00016.71
7.4.10.0080.00816.44
7.4.00.0070.01016.36
7.3.330.0060.00015.95
7.3.320.0000.00612.97
7.3.310.0070.00016.32
7.3.300.0030.00316.16
7.3.290.0050.00916.15
7.3.280.0090.00616.20
7.3.260.0060.00916.27
7.3.240.0080.00916.29
7.3.230.0140.00316.32
7.3.210.0060.01616.32
7.3.200.0060.01116.33
7.3.190.0130.00316.11
7.3.180.0100.00616.25
7.3.170.0120.00316.16
7.3.160.0110.00416.23
7.3.130.0030.01116.06
7.3.120.0030.01216.11
7.3.110.0030.01416.09
7.3.100.0080.00816.00
7.3.90.0120.00316.15
7.3.80.0130.00316.26
7.3.70.0040.01116.29
7.3.60.0130.00716.05
7.3.50.0040.01116.09
7.3.40.0120.00316.16
7.3.30.0000.01516.18
7.3.20.0070.00716.21
7.3.10.0110.00316.24
7.3.00.0000.01416.04
7.2.330.0100.00716.11
7.2.320.0120.00316.48
7.2.310.0120.00916.47
7.2.300.0100.01316.53
7.2.290.0100.00616.56
7.2.260.0100.00716.50
7.2.250.0060.00916.21
7.2.240.0130.00316.39
7.2.230.0030.01216.31
7.2.220.0030.01216.39
7.2.210.0070.01016.27
7.2.200.0080.00916.34
7.2.190.0090.00616.34
7.2.180.0040.01116.11
7.2.170.0090.00616.20
7.2.160.0040.01116.06
7.2.150.0120.00316.23
7.2.140.0090.00616.18
7.2.130.0120.00416.43
7.2.120.0120.00316.43
7.2.110.0130.00316.22
7.2.100.0070.01016.29
7.2.90.0090.00616.15
7.2.80.0110.00416.35
7.2.70.0110.00416.48
7.2.60.0040.01116.46
7.2.50.0070.01016.32
7.2.40.0120.00816.29
7.2.30.0030.01816.39
7.2.20.0100.01016.41
7.2.10.0100.01016.21
7.2.00.0140.00616.35

preferences:
56.62 ms | 400 KiB | 5 Q