3v4l.org

run code in 300+ PHP versions simultaneously
<?php function interpreter(string $code, int $iterations, int $width, int $height): string { $dataGrid = []; $output = ''; $codeOffset = -1; $skip = 0; $commands = $code; $pointer = ['x' => 0, 'y' => 0]; $jmps = new SplStack(); for ($row = 0; $row < $width; ++$row) { for ($col = 0; $col < $height; ++$col) { $dataGrid[$col][$row] = '0'; } } while (strlen($commands) && $iterations) { if (!$skip) echo "{$commands} ({$pointer['x']}, {$pointer['y']} = {$dataGrid[$pointer['x']][$pointer['y']]})\n"; ++$codeOffset; $command = $commands[0]; $commands = substr($commands, 1); if ($skip) { if ($command === ']') { $jmps->pop(); var_dump("pop"); --$skip; } elseif ($command === '[') { ++$skip; } continue; } //var_dump($command); switch ($command) { case 'n': if (--$pointer['x'] === -1) { $pointer['x'] = $height - 1; } break; case 'e': if (++$pointer['y'] === $width) { $pointer['y'] = 0; } break; case 's': if (++$pointer['x'] === $height) { $pointer['x'] = 0; } break; case 'w': if (--$pointer['y'] === -1) { $pointer['y'] = $width - 1; } break; case '*': if ($dataGrid[$pointer['x']][$pointer['y']] === '0') { echo "{$pointer['x']}, {$pointer['y']} = 1\n"; $dataGrid[$pointer['x']][$pointer['y']] = '1'; } else { echo "{$pointer['x']}, {$pointer['y']} = 0\n"; $dataGrid[$pointer['x']][$pointer['y']] = '0'; } break; case '[': $jmps->push($codeOffset); var_dump("push"); if ($dataGrid[$pointer['x']][$pointer['y']] === '0') { $skip = 1; } break; case ']': $jmpOffset = $jmps->top(); var_dump("pop"); if ($dataGrid[$pointer['x']][$pointer['y']] === '1') { $commands = substr($code, $jmpOffset + 1); $codeOffset = $jmpOffset; // ++$iterations; } break; default: continue 2; } --$iterations; } $rows = []; foreach ($dataGrid as $row) { $rows[] = implode('', $row); } return implode("\r\n", $rows); } var_dump(interpreter("*[es*]", 52, 5, 6)); /* 11000 01100 00110 00011 00001 10000*/ // var_dump(interpreter("*[s[e]*]", 9, 5, 5)); /*10000 10000 00000 00000 00000*/

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.0150.00418.55
8.3.50.0040.01118.20
8.3.40.0120.00318.72
8.3.30.0120.00318.81
8.3.20.0000.00821.73
8.3.10.0080.00021.85
8.3.00.0030.00619.26
8.2.180.0060.01518.41
8.2.170.0120.00322.96
8.2.160.0070.00720.43
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0070.00718.03
8.2.120.0070.00026.35
8.2.110.0090.00021.95
8.2.100.0000.01217.97
8.2.90.0060.00317.63
8.2.80.0030.00617.97
8.2.70.0040.00418.04
8.2.60.0040.00418.09
8.2.50.0040.00418.10
8.2.40.0000.00820.36
8.2.30.0050.00219.24
8.2.20.0040.00418.12
8.2.10.0050.00318.30
8.2.00.0050.00317.80
8.1.280.0070.01425.92
8.1.270.0040.00423.77
8.1.260.0060.00326.35
8.1.250.0100.00728.09
8.1.240.0060.00323.92
8.1.230.0060.00619.11
8.1.220.0000.00817.80
8.1.210.0030.00618.77
8.1.200.0080.00317.48
8.1.190.0040.00417.35
8.1.180.0060.00318.10
8.1.170.0040.00418.98
8.1.160.0040.00418.86
8.1.150.0040.00420.32
8.1.140.0000.00819.55
8.1.130.0000.00718.98
8.1.120.0070.00017.43
8.1.110.0040.00417.50
8.1.100.0000.00817.55
8.1.90.0030.00617.43
8.1.80.0000.00717.47
8.1.70.0030.00317.50
8.1.60.0040.00417.65
8.1.50.0000.00917.54
8.1.40.0040.00417.61
8.1.30.0000.00817.67
8.1.20.0040.00417.62
8.1.10.0030.00617.57
8.1.00.0050.00317.58
8.0.300.0040.00419.54
8.0.290.0000.00816.88
8.0.280.0030.00318.56
8.0.270.0000.00716.87
8.0.260.0040.00417.17
8.0.250.0000.00717.03
8.0.240.0040.00416.97
8.0.230.0070.00016.94
8.0.220.0050.00316.92
8.0.210.0040.00416.91
8.0.200.0000.00716.96
8.0.190.0070.00317.03
8.0.180.0000.00716.94
8.0.170.0030.00516.95
8.0.160.0000.00716.98
8.0.150.0030.00516.88
8.0.140.0040.00416.88
8.0.130.0050.00213.36
8.0.120.0050.00316.81
8.0.110.0070.00016.96
8.0.100.0040.00416.81
8.0.90.0020.00516.79
8.0.80.0060.01316.95
8.0.70.0070.00016.98
8.0.60.0080.00016.84
8.0.50.0000.00717.00
8.0.30.0060.01216.95
8.0.20.0110.00917.44
8.0.10.0000.00717.10
8.0.00.0100.00716.87
7.4.330.0000.00515.55
7.4.320.0000.00616.65
7.4.300.0000.00616.64
7.4.290.0030.00316.61
7.4.280.0040.00416.57
7.4.270.0000.00716.61
7.4.260.0040.00416.45
7.4.250.0040.00416.63
7.4.240.0000.00716.48
7.4.230.0030.00316.54
7.4.220.0090.00916.56
7.4.210.0130.01016.76
7.4.200.0050.00216.66
7.4.160.0120.00416.50
7.4.150.0090.01517.40
7.4.140.0130.00617.86
7.4.130.0090.01016.57
7.4.120.0090.01516.51
7.4.110.0150.00416.51
7.4.100.0180.00416.51
7.4.90.0080.01116.43
7.4.80.0100.01019.39
7.4.70.0080.01116.51
7.4.60.0040.01316.40
7.4.50.0090.00616.58
7.4.40.0070.01016.54
7.4.30.0100.00716.55
7.4.00.0080.00815.15
7.3.330.0000.00513.39
7.3.320.0000.00513.28
7.3.310.0030.00316.29
7.3.300.0040.00416.38
7.3.290.0070.00816.40
7.3.280.0130.00716.44
7.3.270.0080.01217.40
7.3.260.0150.00616.50
7.3.250.0080.01016.58
7.3.240.0080.01116.55
7.3.230.0140.00416.46
7.3.210.0180.00616.33
7.3.200.0070.01116.54
7.3.190.0090.00916.47
7.3.180.0080.01116.73
7.3.170.0140.00916.46
7.3.160.0130.01216.72
7.3.120.0110.00314.88
7.3.110.0060.00614.97
7.3.100.0030.00914.67
7.3.90.0030.01214.85
7.3.80.0090.00315.11
7.3.70.0110.00315.07
7.3.60.0070.00714.93
7.3.50.0080.00814.77
7.3.40.0040.00814.82
7.3.30.0110.00414.82
7.3.20.0060.00616.67
7.3.10.0070.00416.64
7.3.00.0090.00616.63
7.2.330.0190.00316.93
7.2.320.0060.01216.63
7.2.310.0100.00916.55
7.2.300.0100.01416.82
7.2.290.0090.00916.84
7.2.240.0030.00615.07
7.2.230.0060.00615.25
7.2.220.0000.01214.92
7.2.210.0060.01015.09
7.2.200.0070.00715.17
7.2.190.0030.00615.23
7.2.180.0070.00414.98
7.2.170.0000.01714.86
7.2.160.0000.01215.26
7.2.150.0130.00316.71
7.2.140.0040.01217.09
7.2.130.0110.00316.67
7.2.120.0070.00716.73
7.2.110.0130.00316.74
7.2.100.0040.01416.88
7.2.90.0070.00416.89
7.2.80.0030.01016.80
7.2.70.0040.01117.09
7.2.60.0070.00716.95
7.2.50.0030.01017.11
7.2.40.0000.01716.95
7.2.30.0060.00917.09
7.2.20.0040.01216.65
7.2.10.0030.01316.90
7.2.00.0040.00716.87
7.1.330.0070.00715.92
7.1.320.0070.00415.52
7.1.310.0000.01115.85
7.1.300.0030.00715.86
7.1.290.0060.00615.64
7.1.280.0050.00515.76
7.1.270.0000.01315.57
7.1.260.0070.01015.67
7.1.250.0060.00315.74
7.1.200.0040.00815.66
7.1.70.0050.00517.15
7.1.60.0070.00716.91
7.1.50.0030.01917.00
7.1.10.0130.08022.25
7.1.00.0070.06022.27
7.0.200.0100.01016.58
7.0.150.0130.07721.86
7.0.140.0070.05721.83
7.0.130.0070.05721.81
7.0.120.0100.05721.77
7.0.110.0070.06021.88
7.0.100.0070.05721.79
7.0.90.0030.06021.88
7.0.80.0070.05721.79
7.0.70.0070.05721.94
7.0.60.0070.05721.73
7.0.50.0100.05321.89
7.0.40.0030.05721.88
7.0.30.0000.06321.83
7.0.20.0200.04321.87
7.0.10.0130.05021.71
7.0.00.0030.06021.81

preferences:
48.76 ms | 401 KiB | 5 Q