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"; function boolString($bool) { if ($bool) return "true"; return "false"; } foreach ($lexedList as $key => $lexed) { //$lexed[0] = str_replace('is_string', 'is_string($test)', $lexed[0]); $lexed[1] = str_replace('is_string', boolString(is_string($test)), $lexed[1]); $lexed[1] = str_replace('is_bool', boolString(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.70.0120.00318.68
8.3.60.0060.00918.43
8.3.50.0110.00821.28
8.3.40.0150.00018.76
8.3.30.0100.01018.84
8.3.20.0080.00020.25
8.3.10.0040.00423.61
8.3.00.0100.00020.24
8.2.190.0090.00918.29
8.2.180.0150.00618.29
8.2.170.0120.00322.96
8.2.160.0070.01420.50
8.2.150.0110.00725.66
8.2.140.0040.00424.66
8.2.130.0000.00926.16
8.2.120.0060.00317.63
8.2.110.0110.00022.25
8.2.100.0080.00318.16
8.2.90.0080.00019.30
8.2.80.0040.00417.97
8.2.70.0040.00417.75
8.2.60.0050.00318.03
8.2.50.0080.00018.07
8.2.40.0080.00319.31
8.2.30.0040.00420.55
8.2.20.0030.00517.82
8.2.10.0080.00018.17
8.2.00.0040.00418.03
8.1.280.0030.01325.92
8.1.270.0090.00023.84
8.1.260.0040.01126.35
8.1.250.0040.00428.09
8.1.240.0030.00622.52
8.1.230.0040.00817.66
8.1.220.0030.00517.79
8.1.210.0000.00818.77
8.1.200.0070.00317.35
8.1.190.0040.00417.35
8.1.180.0060.00318.10
8.1.170.0080.00018.53
8.1.160.0050.00322.08
8.1.150.0000.00818.91
8.1.140.0100.00017.51
8.1.130.0040.00417.61
8.1.120.0080.00017.37
8.1.110.0000.00817.50
8.1.100.0040.00417.38
8.1.90.0050.00317.50
8.1.80.0040.00417.35
8.1.70.0040.00417.34
8.1.60.0000.00817.61
8.1.50.0050.00317.54
8.1.40.0030.00517.55
8.1.30.0030.00617.57
8.1.20.0000.00817.61
8.1.10.0030.00617.58
8.1.00.0040.00417.51
8.0.300.0090.00018.90
8.0.290.0070.00016.75
8.0.280.0030.00318.53
8.0.270.0070.00017.31
8.0.260.0060.00017.29
8.0.250.0000.00716.91
8.0.240.0000.00717.02
8.0.230.0000.00716.93
8.0.220.0000.00716.99
8.0.210.0030.00516.98
8.0.200.0040.00416.88
8.0.190.0000.00816.90
8.0.180.0080.00016.89
8.0.170.0080.00317.00
8.0.160.0050.00216.95
8.0.150.0070.00016.94
8.0.140.0090.00016.89
8.0.130.0030.00313.33
8.0.120.0040.00416.90
8.0.110.0000.00816.96
8.0.100.0040.00416.79
8.0.90.0020.00516.96
8.0.80.0040.01717.01
8.0.70.0050.00216.84
8.0.60.0000.00716.84
8.0.50.0030.00317.06
8.0.30.0040.01417.10
8.0.20.0120.00717.40
8.0.10.0020.00517.02
8.0.00.0150.00916.77
7.4.330.0000.00515.08
7.4.320.0060.00016.65
7.4.300.0060.00016.52
7.4.290.0030.00516.63
7.4.280.0070.00016.41
7.4.270.0040.00416.62
7.4.260.0000.00716.59
7.4.250.0040.00416.46
7.4.240.0040.00416.50
7.4.230.0040.00416.62
7.4.220.0070.01116.57
7.4.210.0060.00916.65
7.4.200.0040.00416.70
7.4.160.0080.00816.63
7.4.150.0090.01117.40
7.4.140.0070.01217.86
7.4.130.0100.00816.62
7.4.120.0100.01016.57
7.4.110.0080.00816.68
7.4.100.0120.00616.62
7.4.90.0070.01116.51
7.4.80.0190.00319.39
7.4.70.0100.00716.63
7.4.60.0030.01316.59
7.4.50.0000.00516.36
7.4.40.0160.00316.59
7.4.30.0060.01616.45
7.4.00.0110.00415.17
7.3.330.0000.00713.46
7.3.320.0030.00213.25
7.3.310.0040.00416.28
7.3.300.0040.00416.27
7.3.290.0080.00716.42
7.3.280.0090.01016.38
7.3.270.0070.01017.40
7.3.260.0110.01116.53
7.3.250.0050.01216.57
7.3.240.0120.00916.44
7.3.230.0120.00416.39
7.3.210.0090.00916.52
7.3.200.0130.00416.51
7.3.190.0060.01116.53
7.3.180.0060.00916.31
7.3.170.0070.01016.65
7.3.160.0070.01016.55
7.3.00.0130.00516.38
7.2.330.0150.00316.78
7.2.320.0140.00316.82
7.2.310.0070.01016.80
7.2.300.0070.01016.80
7.2.290.0100.00716.86
7.2.130.0030.01316.92
7.2.120.0030.01217.01
7.2.110.0030.01216.67
7.2.100.0060.00916.68
7.2.90.0080.00816.57
7.2.80.0000.01117.02
7.2.70.0090.00617.03
7.2.60.0050.01116.86
7.2.50.0000.01416.93
7.2.40.0090.00616.88
7.2.30.0090.00617.14
7.2.20.0030.01416.96
7.2.10.0060.00616.80
7.2.00.0060.00718.11
7.1.250.0060.00615.98
7.1.240.0030.00715.60
7.1.230.0060.00315.57
7.1.220.0070.00315.80
7.1.210.0030.01015.65
7.1.200.0050.00815.79
7.1.190.0030.01015.79
7.1.180.0000.01115.55
7.1.170.0040.00715.94
7.1.160.0060.00615.66
7.1.150.0090.00615.84
7.1.140.0000.00915.72
7.1.130.0070.01015.72
7.1.120.0060.00615.45
7.1.110.0000.01515.72
7.1.100.0050.00917.06
7.1.90.0030.01315.71
7.1.80.0040.01215.63
7.1.70.0110.00516.39
7.1.60.0120.00717.37
7.1.50.0080.01116.39
7.1.40.0000.01515.80
7.1.30.0110.00415.85
7.1.20.0070.01015.90
7.1.10.0070.01015.74
7.1.00.0020.04519.09
7.0.330.0070.01015.41
7.0.320.0030.00915.39
7.0.310.0030.01315.36
7.0.300.0060.00315.52
7.0.290.0030.00915.43
7.0.280.0000.01315.65
7.0.270.0040.00715.27
7.0.260.0000.01715.35
7.0.250.0080.00415.16
7.0.240.0090.00615.26
7.0.230.0060.00615.46
7.0.220.0040.00415.39
7.0.210.0120.00315.30
7.0.200.0050.00716.10
7.0.190.0070.00715.38
7.0.180.0030.00915.52
7.0.170.0100.00615.57
7.0.160.0140.00315.24
7.0.150.0060.00615.50
7.0.140.0000.01415.43
7.0.130.0090.00615.50
7.0.120.0070.00715.30
7.0.110.0030.01115.53
7.0.100.0080.00815.29
7.0.90.0030.01015.42
7.0.80.0040.00715.46
7.0.70.0080.00315.47
7.0.60.0110.02117.75
7.0.50.0100.03316.61
7.0.40.0070.02416.91
7.0.30.0200.04216.80
7.0.20.0130.03216.80
7.0.10.0050.04816.83
7.0.00.0080.04616.84
5.6.380.0030.00614.17
5.6.370.0030.00914.34
5.6.360.0070.01014.71
5.6.350.0000.01114.32
5.6.340.0000.01714.71
5.6.330.0100.00314.44
5.6.320.0130.00014.64
5.6.310.0100.00714.45
5.6.300.0090.00614.70
5.6.290.0120.00614.82
5.6.280.0080.03517.77
5.6.270.0000.00914.57
5.6.260.0150.00314.40
5.6.250.0040.00714.41
5.6.240.0080.00414.65
5.6.230.0000.01014.45
5.6.220.0070.00714.54
5.6.210.0000.04417.42
5.6.200.0070.02916.33
5.6.190.0080.04817.42
5.6.180.0190.04017.73
5.6.170.0180.03517.46
5.6.160.0090.04117.55
5.6.150.0020.02616.35
5.6.140.0070.03016.33
5.6.130.0080.04016.41
5.6.120.0110.03317.84
5.6.110.0050.02917.81
5.6.100.0020.02617.70
5.6.90.0030.02717.75
5.6.80.0060.03817.48
5.6.70.0000.01514.33
5.6.60.0060.00614.47
5.6.50.0110.00414.25
5.6.40.0120.00014.54
5.6.30.0060.00614.52
5.6.20.0080.00614.50
5.6.10.0070.01014.53
5.6.00.0070.01014.38
5.5.380.0060.00611.36
5.5.370.0060.00311.20
5.5.360.0030.00611.43
5.5.350.0030.02815.99
5.5.340.0080.04114.71
5.5.330.0050.02315.88
5.5.320.0160.04115.86
5.5.310.0240.03815.85
5.5.300.0060.02114.78
5.5.290.0070.04314.76
5.5.280.0100.04016.13
5.5.270.0070.04216.06
5.5.260.0050.04616.04
5.5.250.0070.01816.01
5.5.240.1740.02415.80
5.5.230.0040.00411.36
5.5.220.0100.00011.21
5.5.210.0000.00611.20
5.5.200.0040.00411.21
5.5.190.0040.00411.28
5.5.180.0060.00011.51
5.5.170.0000.00911.27
5.5.160.0060.00311.33
5.5.150.0050.00211.44
5.5.140.0080.00411.34
5.5.130.0030.01010.88
5.5.120.0060.00611.48
5.5.110.0080.00311.20
5.5.100.0030.00511.51
5.5.90.0030.00611.25
5.5.80.0000.00611.36
5.5.70.0070.00311.09
5.5.60.0060.00311.42
5.5.50.0110.00011.41
5.5.40.0060.00611.45
5.5.30.0030.00711.17
5.5.20.0110.00011.54
5.5.10.0030.01011.16
5.5.00.0080.00311.29
5.4.450.0380.03115.43
5.4.440.0420.03215.31
5.4.430.0440.02715.45
5.4.420.0430.02515.09
5.4.410.0400.03015.06
5.4.400.0400.02815.28
5.4.390.0400.02814.92
5.4.380.0320.03715.28
5.4.370.0370.03115.14
5.4.360.0400.02915.19
5.4.350.0400.03215.08
5.4.340.0430.03315.36
5.4.330.0030.01010.91
5.4.320.0360.03415.17
5.4.310.0370.03014.96
5.4.300.0410.02615.35
5.4.290.0400.03215.08
5.4.280.0480.02815.23
5.4.270.0410.02515.18
5.4.260.0370.02815.31
5.4.250.0350.03215.20
5.4.240.0330.03315.17
5.4.230.0380.02815.07
5.4.220.0400.02915.02
5.4.210.0410.02615.13
5.4.200.0370.03015.35
5.4.190.0380.03215.15
5.4.180.0400.02715.12
5.4.170.0400.02514.95
5.4.160.0410.02515.20
5.4.150.0400.02815.26
5.4.140.0400.03014.06
5.4.130.0390.02713.82
5.4.120.0320.03413.88
5.4.110.0370.02913.94
5.4.100.0390.02713.87
5.4.90.0490.03313.86
5.4.80.0430.02313.93
5.4.70.0070.02513.99
5.4.60.0090.02513.77
5.4.50.0030.04113.59
5.4.40.0170.03513.69
5.4.30.0150.03913.84
5.4.20.0180.03313.86
5.4.10.0050.00310.89
5.4.00.0000.00910.84

preferences:
67.55 ms | 401 KiB | 5 Q