3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Trie { public $data = []; public $value = false; } $tokens = [ "apple" => "T_APPLE", "ape" => "T_APE", "cape" => "T_CAPE", "(" => "T_L_PARENTH", ")" => "T_R_PARENTH", "is_string" => "T_IS_STRING", "is_bool" => "T_IS_BOOL", "!is_bool" => "T_NOT_IS_BOOL", "&" => "T_AND", "|" => "T_OR", ]; $root = new Trie; foreach ($tokens as $name => $value) { $node = $root; // For each character in the string for ($i = 0; $i < strlen($name); $i++) { $char = $name[$i]; if (!isset($node->data[$char])) { // If we don't have a child with that char // Create it $node->data[$char] = new Trie; } // Reset the node for the next character $node = $node->data[$char]; } // Finally, set the value on the final node $node->value = $value; } function lex($string, Trie $root) { $length = strlen($string); $i = 0; $tokens = []; $node = $root; $buffer = ''; // We want to iterate over the entire string. while ($i < $length) { // Get the current character $char = $string[$i]; if (isset($node->data[$char])) { // We have a valid next character $i++; // Save the character in the buffer $buffer .= $char; // Move to the next state $node = $node->data[$char]; } elseif ($node->value) { // We have a value and no valid next character // Emit the token $tokens[] = [$node->value, $buffer]; // Clear the buffer $buffer = ''; // Reset back to the root for the next token $node = $root; } else { // We can't continue parsing this node throw new Exception("Syntax error at offset $i"); } } if ($buffer !== '') { // We finished without flushing one token if ($node->value) { $tokens[] = [$node->value, $buffer]; } else { // Not a valid complete token throw new Exception("Syntax error at offset $i"); } } return $tokens; } // var_dump(lex('(is_string)', $root)); $lexedList = lex('(is_string)&(is_string|!is_bool)', $root); // get stuff between each parenth, put them in things, then use the & / | to compare the two //var_dump($lexedList); $test = "fuck"; foreach ($lexedList as $key => $lexed) { //$lexed[0] = str_replace('is_string', 'is_string($test)', $lexed[0]); $lexed[1] = str_replace('is_string', is_string($test), $lexed[1]); $lexed[1] = str_replace('is_bool', is_bool($test), $lexed[1]); $lexedList[$key] = $lexed[1]; } //var_dump($lexedList); $eh = implode("", $lexedList); var_dump($eh); $result = eval($eh); var_dump($result);

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.0120.00318.68
8.3.50.0090.00916.49
8.3.40.0080.00818.92
8.3.30.0140.00718.96
8.3.20.0070.01120.46
8.3.10.0060.00323.79
8.3.00.0000.01020.20
8.2.180.0090.00618.09
8.2.170.0120.00322.96
8.2.160.0170.00320.44
8.2.150.0060.01225.66
8.2.140.0050.00324.66
8.2.130.0060.00326.16
8.2.120.0030.00617.62
8.2.110.0050.00522.25
8.2.100.0040.00818.05
8.2.90.0040.00419.35
8.2.80.0070.00417.97
8.2.70.0030.00517.63
8.2.60.0040.00418.05
8.2.50.0040.00418.07
8.2.40.0040.00819.41
8.2.30.0040.00420.63
8.2.20.0000.00917.71
8.2.10.0000.00718.02
8.2.00.0030.00618.18
8.1.280.0060.00925.92
8.1.270.0000.00823.87
8.1.260.0060.00326.35
8.1.250.0130.00628.09
8.1.240.0060.00322.59
8.1.230.0060.00617.68
8.1.220.0030.00517.79
8.1.210.0030.00518.77
8.1.200.0060.00317.35
8.1.190.0040.00417.35
8.1.180.0000.00818.10
8.1.170.0000.00918.61
8.1.160.0000.00721.95
8.1.150.0040.00418.91
8.1.140.0070.00317.48
8.1.130.0040.00417.75
8.1.120.0000.00717.50
8.1.110.0040.00417.49
8.1.100.0000.00717.46
8.1.90.0050.00217.43
8.1.80.0080.00017.34
8.1.70.0000.00717.46
8.1.60.0040.00417.49
8.1.50.0030.00517.59
8.1.40.0030.00617.42
8.1.30.0040.00417.67
8.1.20.0000.00917.56
8.1.10.0040.00417.57
8.1.00.0040.00417.38
8.0.300.0060.00318.77
8.0.290.0000.00716.75
8.0.280.0070.00018.45
8.0.270.0030.00317.33
8.0.260.0070.00017.27
8.0.250.0050.00316.93
8.0.240.0000.00717.05
8.0.230.0040.00417.05
8.0.220.0050.00217.00
8.0.210.0040.00416.95
8.0.200.0040.00417.00
8.0.190.0040.00417.02
8.0.180.0000.00816.82
8.0.170.0040.00416.94
8.0.160.0000.00717.04
8.0.150.0000.00716.86
8.0.140.0090.00016.86
8.0.130.0000.00613.46
8.0.120.0050.00516.84
8.0.110.0050.00316.92
8.0.100.0080.00017.03
8.0.90.0040.00416.80
8.0.80.0090.00616.95
8.0.70.0030.00516.80
8.0.60.0040.00416.82
8.0.50.0070.00016.85
8.0.30.0090.00917.24
8.0.20.0100.00917.40
8.0.10.0000.00716.98
8.0.00.0100.01116.91
7.4.330.0050.00015.26
7.4.320.0070.00016.57
7.4.300.0000.00616.56
7.4.290.0000.00716.41
7.4.280.0030.00316.52
7.4.270.0000.00716.62
7.4.260.0080.00016.59
7.4.250.0040.00416.47
7.4.240.0030.00416.51
7.4.230.0040.00416.52
7.4.220.0080.01116.46
7.4.210.0140.00316.59
7.4.200.0000.00716.56
7.4.160.0030.01316.48
7.4.150.0090.00917.40
7.4.140.0130.00517.86
7.4.130.0140.00616.52
7.4.120.0110.00716.66
7.4.110.0160.00616.66
7.4.100.0070.01116.68
7.4.90.0110.01216.45
7.4.80.0070.01419.39
7.4.70.0170.00716.62
7.4.60.0080.00816.55
7.4.50.0030.00616.36
7.4.40.0100.00716.71
7.4.30.0060.01416.63
7.4.00.0040.01214.98
7.3.330.0000.00613.39
7.3.320.0000.00513.23
7.3.310.0000.00716.34
7.3.300.0030.00316.41
7.3.290.0070.00816.40
7.3.280.0100.00916.46
7.3.270.0110.00917.40
7.3.260.0040.01216.63
7.3.250.0090.00816.43
7.3.240.0140.00916.48
7.3.230.0140.00316.55
7.3.210.0030.01316.48
7.3.200.0090.01016.78
7.3.190.0120.00616.39
7.3.180.0060.01116.48
7.3.170.0070.01016.42
7.3.160.0100.01216.63
7.2.330.0030.01416.68
7.2.320.0070.01016.91
7.2.310.0040.01416.75
7.2.300.0060.01216.77
7.2.290.0070.01016.48
7.2.60.0030.01017.11
7.2.00.0060.00619.39
7.1.200.0060.00615.99
7.1.100.0040.00718.17
7.1.70.0110.00017.26
7.1.60.0110.01419.29
7.1.50.0040.02116.80
7.1.00.0030.07722.43
7.0.200.0000.01016.54
7.0.60.0130.08019.92
7.0.50.0100.03317.91
7.0.40.0170.04020.30
7.0.30.0230.05020.02
7.0.20.0300.05020.09
7.0.10.0070.05320.05
7.0.00.0030.05320.33
5.6.280.0100.06320.84
5.6.210.0030.07020.78
5.6.200.0030.08718.16
5.6.190.0100.03720.58
5.6.180.0500.04320.77
5.6.170.0330.06720.47
5.6.160.0070.08320.48
5.6.150.0170.07318.19
5.6.140.0000.05718.28
5.6.130.0070.08318.26
5.6.120.0130.04720.99
5.6.110.0000.04721.01
5.6.100.0070.08721.09
5.6.90.0070.03721.10
5.6.80.0130.07720.41
5.5.350.0170.04320.55
5.5.340.0030.08017.93
5.5.330.0070.08020.41
5.5.320.0300.06020.35
5.5.310.0200.06020.30
5.5.300.0170.04718.06
5.5.290.0070.08317.97
5.5.280.0070.06720.79
5.5.270.0100.08320.86
5.5.260.0000.06320.77
5.5.250.0100.04020.71
5.5.240.0200.04320.25
5.4.450.0230.04719.58
5.4.440.0130.05719.47
5.4.430.0230.06719.29
5.4.420.0170.06019.20
5.4.410.0230.06019.20
5.4.400.0330.05018.98
5.4.390.0270.05019.25
5.4.380.0330.04019.29
5.4.370.0200.05319.28
5.4.360.0230.05319.14
5.4.350.0270.04719.01
5.4.340.0130.06319.28
5.4.320.0230.05019.30
5.4.310.0170.05319.23
5.4.300.0300.06319.14
5.4.290.0370.03718.86
5.4.280.0270.04719.00
5.4.270.0230.05019.28
5.4.260.0330.04019.16
5.4.250.0170.05719.36
5.4.240.0270.05019.27
5.4.230.0100.06319.04
5.4.220.0230.07719.31
5.4.210.0230.05719.36
5.4.200.0230.05319.13
5.4.190.0270.05019.39
5.4.180.0300.05019.11
5.4.170.0200.05719.36
5.4.160.0300.04719.26
5.4.150.0170.05719.23
5.4.140.0170.05716.36
5.4.130.0270.04316.45
5.4.120.0230.04716.61
5.4.110.0100.06316.48
5.4.100.0100.06016.68
5.4.90.0230.05016.68
5.4.80.0170.05316.66
5.4.70.0070.06716.57
5.4.60.0200.03316.57
5.4.50.0100.06316.56
5.4.40.0330.06316.50
5.4.30.0200.07316.39
5.4.20.0270.04016.44

preferences:
55.87 ms | 400 KiB | 5 Q