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.0130.01018.41
8.3.50.0110.00822.01
8.3.40.0110.00418.84
8.3.30.0120.00318.68
8.3.20.0000.00821.77
8.3.10.0040.00421.91
8.3.00.0060.00319.26
8.2.180.0110.01118.41
8.2.170.0150.00022.96
8.2.160.0070.00720.21
8.2.150.0050.00324.18
8.2.140.0090.00024.66
8.2.130.0090.00618.09
8.2.120.0040.00426.35
8.2.110.0030.00622.01
8.2.100.0060.00618.03
8.2.90.0050.00317.62
8.2.80.0000.01018.09
8.2.70.0080.00017.90
8.2.60.0040.00418.16
8.2.50.0040.00418.10
8.2.40.0040.00420.55
8.2.30.0060.00319.36
8.2.20.0000.00818.21
8.2.10.0050.00318.06
8.2.00.0060.00317.85
8.1.280.0070.01425.92
8.1.270.0060.00320.51
8.1.260.0060.00326.35
8.1.250.0110.00728.09
8.1.240.0030.00623.58
8.1.230.0080.00419.22
8.1.220.0050.00317.78
8.1.210.0030.00618.77
8.1.200.0070.00317.48
8.1.190.0060.00317.47
8.1.180.0040.00418.10
8.1.170.0060.00319.01
8.1.160.0040.00418.95
8.1.150.0040.00420.32
8.1.140.0030.00519.64
8.1.130.0030.00319.09
8.1.120.0000.00717.51
8.1.110.0050.00317.54
8.1.100.0040.00417.42
8.1.90.0000.00817.50
8.1.80.0020.00517.49
8.1.70.0000.00717.52
8.1.60.0080.00017.61
8.1.50.0000.00817.58
8.1.40.0050.00317.56
8.1.30.0040.00417.68
8.1.20.0000.00817.65
8.1.10.0040.00417.70
8.1.00.0000.00817.59
8.0.300.0070.00319.65
8.0.290.0060.00316.88
8.0.280.0000.00718.42
8.0.270.0030.00317.28
8.0.260.0040.00417.23
8.0.250.0030.00317.08
8.0.240.0070.00017.03
8.0.230.0000.00716.92
8.0.220.0070.00016.79
8.0.210.0000.00716.96
8.0.200.0000.00716.88
8.0.190.0110.00016.98
8.0.180.0000.00716.96
8.0.170.0000.00816.99
8.0.160.0040.00416.94
8.0.150.0070.00016.93
8.0.140.0080.00016.93
8.0.130.0030.00613.34
8.0.120.0000.00716.94
8.0.110.0070.00016.81
8.0.100.0040.00417.01
8.0.90.0000.00816.93
8.0.80.0090.00616.87
8.0.70.0040.00416.84
8.0.60.0050.00316.82
8.0.50.0030.00616.83
8.0.30.0070.01117.34
8.0.20.0100.01017.41
8.0.10.0040.00417.15
8.0.00.0130.00416.89
7.4.330.0020.00215.55
7.4.320.0000.00616.70
7.4.300.0030.00316.65
7.4.290.0050.00316.70
7.4.280.0000.00716.65
7.4.270.0000.00716.61
7.4.260.0030.00316.57
7.4.250.0040.00416.57
7.4.240.0000.00716.45
7.4.230.0070.00016.57
7.4.220.0000.01816.56
7.4.210.0070.01116.68
7.4.200.0000.00716.52
7.4.160.0070.01016.39
7.4.150.0130.01317.40
7.4.140.0110.00817.86
7.4.130.0120.00516.53
7.4.120.0030.01616.51
7.4.110.0080.00816.60
7.4.100.0030.02016.68
7.4.90.0130.00516.71
7.4.80.0090.01319.39
7.4.70.0090.00916.54
7.4.60.0130.00316.55
7.4.50.0100.00716.55
7.4.40.0090.00916.47
7.4.30.0100.00616.52
7.4.00.0070.00914.96
7.3.330.0020.00213.27
7.3.320.0030.00313.23
7.3.310.0000.00716.38
7.3.300.0070.00016.40
7.3.290.0070.00816.44
7.3.280.0120.01016.40
7.3.270.0150.00917.40
7.3.260.0110.00916.57
7.3.250.0110.01116.55
7.3.240.0080.01416.46
7.3.230.0140.00416.45
7.3.210.0080.01616.33
7.3.200.0120.01216.58
7.3.190.0130.00316.38
7.3.180.0050.01116.61
7.3.170.0080.00816.57
7.3.160.0130.00716.49
7.3.120.0090.00914.88
7.3.110.0060.01014.97
7.3.100.0100.00715.00
7.3.90.0100.00514.85
7.3.80.0080.00614.92
7.3.70.0040.00814.94
7.3.60.0030.01015.01
7.3.50.0070.00814.84
7.3.40.0080.00614.84
7.3.30.0060.00714.74
7.3.20.0020.01216.71
7.3.10.0050.00916.62
7.3.00.0040.00816.69
7.2.330.0080.01116.85
7.2.320.0060.01216.77
7.2.310.0140.00316.49
7.2.300.0060.01916.77
7.2.290.0080.01216.94
7.2.250.0100.01015.16
7.2.240.0080.00915.17
7.2.230.0060.00915.14
7.2.220.0060.00715.22
7.2.210.0040.01315.23
7.2.200.0030.01115.18
7.2.190.0040.01215.01
7.2.180.0070.00714.96
7.2.170.0060.01015.04
7.2.160.0090.00815.08
7.2.150.0060.00916.98
7.2.140.0090.00816.74
7.2.130.0080.00817.00
7.2.120.0070.00916.79
7.2.110.0040.01116.94
7.2.100.0060.00716.89
7.2.90.0080.00916.96
7.2.80.0050.00916.88
7.2.70.0060.00616.97
7.2.60.0070.00716.88
7.2.50.0060.00816.88
7.2.40.0030.01016.90
7.2.30.0110.00216.87
7.2.20.0050.00916.89
7.2.10.0030.00917.08
7.2.00.0020.00917.81
7.1.330.0050.00815.89
7.1.320.0040.01015.81
7.1.310.0060.00515.86
7.1.300.0060.00915.83
7.1.290.0030.00915.94
7.1.280.0070.00715.77
7.1.270.0100.00515.82
7.1.260.0070.00715.75
7.1.250.0070.00515.85
7.1.240.0070.01015.71
7.1.230.0030.00715.84
7.1.220.0000.01415.66
7.1.210.0040.00415.72
7.1.200.0040.00915.94
7.1.190.0030.01016.06
7.1.180.0040.00815.74
7.1.170.0030.00615.78
7.1.160.0000.00915.61
7.1.150.0090.00015.78
7.1.140.0070.00715.88
7.1.130.0060.00615.84
7.1.120.0030.01215.64
7.1.110.0040.01115.78
7.1.100.0050.00816.90
7.1.90.0000.01415.86
7.1.80.0100.00315.88
7.1.70.0010.01216.47
7.1.60.0070.00816.56
7.1.50.0020.01716.41
7.1.40.0080.00415.90
7.1.30.0060.00315.94
7.1.20.0090.00415.83
7.1.10.0120.02819.12
7.1.00.0080.03219.07
7.0.330.0060.00615.16
7.0.320.0070.00715.37
7.0.310.0030.00915.45
7.0.300.0000.01415.18
7.0.290.0000.00915.55
7.0.280.0060.00315.48
7.0.270.0070.00715.59
7.0.260.0040.01115.34
7.0.250.0090.00615.48
7.0.240.0060.00915.26
7.0.230.0030.01015.29
7.0.220.0070.00715.32
7.0.210.0070.00715.26
7.0.200.0080.01416.11
7.0.190.0130.00315.48
7.0.180.0060.00315.27
7.0.170.0030.01315.29
7.0.160.0080.00615.25
7.0.150.0030.03518.54
7.0.140.0020.03618.66
7.0.130.0050.03418.62
7.0.120.0070.03218.63
7.0.110.0020.03818.69
7.0.100.0050.03218.56
7.0.90.0070.03318.60
7.0.80.0090.02818.66
7.0.70.0030.03518.68
7.0.60.0080.03018.68
7.0.50.0110.02718.77
7.0.40.0050.03317.60
7.0.30.0050.03117.67
7.0.20.0080.02817.64
7.0.10.0110.03517.59
7.0.00.0050.03317.58
5.6.400.0060.00614.39
5.6.390.0070.00714.23
5.6.380.0000.00814.11
5.6.370.0100.00314.31
5.6.360.0040.01213.93
5.6.350.0060.00614.07
5.6.340.0060.00614.11
5.6.330.0060.00314.41
5.6.320.0100.00714.24
5.6.310.0060.00914.21
5.6.300.0040.00814.45
5.6.290.0030.00914.11
5.6.280.0030.00714.50
5.6.270.0090.00414.26
5.6.260.0080.00414.46
5.6.250.0040.00414.09
5.6.240.0060.00814.31
5.6.230.0040.00714.20
5.6.220.0000.00814.07
5.6.210.0070.00713.99
5.6.200.0030.01014.22
5.6.190.0070.00314.46
5.6.180.0040.01114.10
5.6.170.0000.00814.17
5.6.160.0100.00313.79
5.6.150.0040.00714.13
5.6.140.0070.00714.13
5.6.130.0110.00014.29
5.6.120.0030.01013.99
5.6.110.0120.00313.91
5.6.100.0090.00614.05
5.6.90.0060.00614.19
5.6.80.0080.00414.11
5.6.70.0030.01013.97
5.6.60.0060.00913.91
5.6.50.0070.00713.88
5.6.40.0040.00714.28
5.6.30.0090.00314.29
5.6.20.0070.00713.82
5.6.10.0030.01313.96
5.6.00.0030.00614.11

preferences:
63.62 ms | 401 KiB | 5 Q