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); 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]); $lexedList[$key] = $lexed; } //var_dump($lexedList); $test = "fuck"; $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.0000.02218.55
8.3.50.0120.00616.31
8.3.40.0150.00618.96
8.3.30.0090.00918.89
8.3.20.0030.01220.08
8.3.10.0000.00923.52
8.3.00.0060.00320.29
8.2.180.0060.01616.88
8.2.170.0070.00722.96
8.2.160.0090.00920.32
8.2.150.0070.01125.66
8.2.140.0080.00024.66
8.2.130.0090.00026.16
8.2.120.0090.00017.63
8.2.110.0060.00319.24
8.2.100.0090.00317.91
8.2.90.0000.00818.16
8.2.80.0050.00318.34
8.2.70.0050.00318.05
8.2.60.0030.01018.04
8.2.50.0070.00518.10
8.2.40.0000.00820.60
8.2.30.0040.00420.61
8.2.20.0040.00417.70
8.2.10.0050.00518.15
8.2.00.0050.00318.18
8.1.280.0040.01125.92
8.1.270.0130.00323.84
8.1.260.0160.00026.35
8.1.250.0060.00928.09
8.1.240.0040.00422.54
8.1.230.0000.01320.96
8.1.220.0040.00417.79
8.1.210.0000.00818.94
8.1.200.0050.00517.35
8.1.190.0030.00617.36
8.1.180.0080.00018.10
8.1.170.0030.00618.59
8.1.160.0040.00422.06
8.1.150.0070.00018.89
8.1.140.0030.00717.48
8.1.130.0040.00417.70
8.1.120.0000.00717.45
8.1.110.0080.00017.34
8.1.100.0070.00017.50
8.1.90.0040.00417.50
8.1.80.0040.00417.39
8.1.70.0000.00817.50
8.1.60.0000.00717.53
8.1.50.0060.00317.55
8.1.40.0080.00017.49
8.1.30.0000.00817.68
8.1.20.0050.00517.68
8.1.10.0040.00417.56
8.1.00.0050.00317.57
8.0.300.0060.00319.85
8.0.290.0050.00216.75
8.0.280.0000.00818.50
8.0.270.0040.00417.28
8.0.260.0000.00717.31
8.0.250.0000.00817.02
8.0.240.0050.00317.05
8.0.230.0000.00817.00
8.0.220.0000.00716.98
8.0.210.0000.01016.92
8.0.200.0000.00717.01
8.0.190.0040.00417.00
8.0.180.0000.00816.93
8.0.170.0040.00716.96
8.0.160.0000.00716.99
8.0.150.0000.00816.80
8.0.140.0030.00516.81
8.0.130.0000.00513.40
8.0.120.0040.00416.91
8.0.110.0050.00316.87
8.0.100.0020.00516.80
8.0.90.0000.00716.93
8.0.80.0060.01016.92
8.0.70.0000.00716.84
8.0.60.0000.00716.86
8.0.50.0040.00416.84
8.0.30.0100.01017.19
8.0.20.0090.01117.40
8.0.10.0070.00017.16
8.0.00.0130.00916.71
7.4.330.0020.00215.08
7.4.320.0040.00416.55
7.4.300.0000.00716.42
7.4.290.0000.00716.38
7.4.280.0050.00316.51
7.4.270.0050.00316.57
7.4.260.0000.00716.40
7.4.250.0000.00816.52
7.4.240.0050.00216.52
7.4.230.0040.00416.59
7.4.220.0130.00616.55
7.4.210.0070.00716.60
7.4.200.0000.00716.71
7.4.160.0000.01616.44
7.4.150.0150.00917.40
7.4.140.0070.01217.86
7.4.130.0120.00816.67
7.4.120.0110.00616.58
7.4.110.0090.00916.63
7.4.100.0150.00316.40
7.4.90.0060.01216.57
7.4.80.0150.02019.39
7.4.70.0070.01016.54
7.4.60.0070.01016.48
7.4.50.0030.00616.52
7.4.40.0060.01216.37
7.4.30.0090.01216.68
7.4.10.0060.01214.93
7.4.00.0040.01115.25
7.3.330.0030.00313.45
7.3.320.0000.00513.30
7.3.310.0000.00716.29
7.3.300.0040.00416.30
7.3.290.0050.01216.35
7.3.280.0080.01016.43
7.3.270.0130.00717.40
7.3.260.0110.00616.70
7.3.250.0070.01016.50
7.3.240.0130.00516.51
7.3.230.0100.00716.61
7.3.210.0050.01116.43
7.3.200.0140.00816.64
7.3.190.0070.01016.52
7.3.180.0070.01016.64
7.3.170.0140.00316.56
7.3.160.0080.00816.51
7.3.130.0040.01614.88
7.3.120.0100.00714.90
7.3.110.0070.01115.00
7.3.100.0060.00914.71
7.3.90.0040.00814.91
7.3.80.0060.00314.83
7.3.70.0100.00014.81
7.3.60.0090.00314.69
7.3.50.0100.00715.00
7.3.40.0040.00714.74
7.3.30.0030.01314.91
7.3.20.0060.00616.46
7.3.10.0070.00716.74
7.3.00.0000.01516.70
7.2.330.0090.01216.50
7.2.320.0070.01016.78
7.2.310.0090.00916.55
7.2.300.0030.01316.77
7.2.290.0140.00416.85
7.2.260.0070.01115.02
7.2.250.0120.00615.00
7.2.240.0000.01515.33
7.2.230.0040.01215.25
7.2.220.0030.01215.21
7.2.210.0000.01215.40
7.2.200.0030.01015.01
7.2.190.0060.00615.25
7.2.180.0060.00915.04
7.2.170.0040.01115.18
7.2.160.0030.01415.15
7.2.150.0070.00717.02
7.2.140.0150.00016.77
7.2.130.0090.00616.70
7.2.120.0040.01116.75
7.2.110.0050.00517.07
7.2.100.0030.00617.13
7.2.90.0150.00017.05
7.2.80.0150.00416.97
7.2.70.0060.01216.79
7.2.60.0040.01317.16
7.2.50.0110.00617.02
7.2.40.0080.00416.91
7.2.30.0070.00717.09
7.2.20.0130.00316.76
7.2.10.0060.01017.19
7.2.00.0080.00618.13
7.1.330.0060.00915.98
7.1.320.0030.00915.65
7.1.310.0080.00415.84
7.1.300.0030.01215.85
7.1.290.0070.00715.85
7.1.280.0000.01615.70
7.1.270.0030.00915.90
7.1.260.0070.01015.92
7.1.250.0120.00815.88
7.1.240.0050.00515.97
7.1.230.0030.01215.77
7.1.220.0030.00715.77
7.1.210.0070.01315.91
7.1.200.0050.01015.81
7.1.190.0070.01015.76
7.1.180.0000.01815.84
7.1.170.0030.01315.60
7.1.160.0070.00715.86
7.1.150.0040.01115.59
7.1.140.0070.01115.91
7.1.130.0120.00015.67
7.1.120.0060.00915.71
7.1.110.0080.00815.92
7.1.100.0050.01117.10
7.1.90.0040.01415.85
7.1.80.0060.00916.03
7.1.70.0050.00616.41
7.1.60.0080.01117.53
7.1.50.0060.01116.24
7.1.40.0100.00315.75
7.1.30.0060.00815.93
7.1.20.0060.01015.61
7.1.10.0070.01015.83
7.1.00.0050.04019.10
7.0.330.0070.00715.34
7.0.320.0040.00815.39
7.0.310.0080.00815.44
7.0.300.0030.01015.25
7.0.290.0070.00715.44
7.0.280.0060.00915.43
7.0.270.0060.01015.43
7.0.260.0030.00715.55
7.0.250.0070.00715.42
7.0.240.0090.00615.11
7.0.230.0070.00715.50
7.0.220.0040.01115.47
7.0.210.0040.01115.53
7.0.200.0030.00816.10
7.0.190.0100.00315.46
7.0.180.0000.01715.51
7.0.170.0080.00815.64
7.0.160.0000.00915.50
7.0.150.0000.01415.56
7.0.140.0150.00015.48
7.0.130.0040.01115.18
7.0.120.0060.00915.50
7.0.110.0060.00615.24
7.0.100.0070.00415.32
7.0.90.0030.00915.38
7.0.80.0030.01015.34
7.0.70.0060.01115.42
7.0.60.0090.04617.65
7.0.50.0070.02516.80
7.0.40.0050.02816.79
7.0.30.0200.03316.94
7.0.20.0160.03116.79
7.0.10.0090.03016.87
7.0.00.0020.05016.87
5.6.400.0040.00414.18
5.6.390.0030.01614.39
5.6.380.0100.00714.60
5.6.370.0080.00814.57
5.6.360.0040.01114.45
5.6.350.0030.01014.75
5.6.340.0060.01014.74
5.6.330.0070.00714.47
5.6.320.0060.00314.64
5.6.310.0000.01514.48
5.6.300.0000.01414.40
5.6.290.0060.00914.42
5.6.280.0100.03617.79
5.6.270.0060.00614.63
5.6.260.0150.00314.30
5.6.250.0030.01214.67
5.6.240.0100.00314.51
5.6.230.0070.00714.55
5.6.220.0060.00614.42
5.6.210.0100.04017.70
5.6.200.0090.03116.45
5.6.190.0050.02417.60
5.6.180.0130.03117.48
5.6.170.0220.04217.49
5.6.160.0080.04517.53
5.6.150.0080.04116.35
5.6.140.0000.04516.35
5.6.130.0070.02516.35
5.6.120.0070.02917.81
5.6.110.0030.03317.71
5.6.100.0020.03117.93
5.6.90.0090.04517.85
5.6.80.0060.03417.27
5.6.70.0060.00914.23
5.6.60.0030.01314.42
5.6.50.0000.01514.18
5.6.40.0000.01314.19
5.6.30.0100.00614.36
5.6.20.0040.00814.69
5.6.10.0040.01114.52
5.6.00.0100.00314.71
5.5.380.0110.00314.79
5.5.370.0050.00814.52
5.5.360.0080.00614.45
5.5.350.0020.04417.46
5.5.340.0130.03716.17
5.5.330.0070.02517.46
5.5.320.0160.02317.48
5.5.310.0200.04017.29
5.5.300.0020.02316.29
5.5.290.0030.02816.23
5.5.280.0100.04017.52
5.5.270.0130.04317.53
5.5.260.0030.05117.61
5.5.250.0030.04417.48
5.5.240.2170.02817.36
5.5.230.0030.01014.07
5.5.220.0030.01314.57
5.5.210.0110.00714.63
5.5.200.0070.00714.47
5.5.190.0030.00913.99
5.5.180.0060.01014.50
5.5.170.0100.00314.24
5.5.160.0100.00314.71
5.5.150.0100.00714.30
5.5.140.0120.00314.39
5.5.130.0140.00014.45
5.5.120.0130.00014.33
5.5.110.0070.00314.60
5.5.100.0080.00314.17
5.5.90.0030.01014.30
5.5.80.0060.00914.31
5.5.70.0060.00914.75
5.5.60.0140.00314.26
5.5.50.0000.01614.65
5.5.40.0030.00814.61
5.5.30.0060.01214.34
5.5.20.0110.00714.43
5.5.10.0060.00914.46
5.5.00.0030.01014.00
5.4.450.0300.03515.33
5.4.440.0350.03015.35
5.4.430.0350.03015.54
5.4.420.0330.03315.49
5.4.410.0280.03415.21
5.4.400.0350.02615.04
5.4.390.0330.02815.06
5.4.380.0390.02715.08
5.4.370.0310.03115.18
5.4.360.0310.03015.19
5.4.350.0300.03115.12
5.4.340.0370.02715.17
5.4.330.0040.00811.01
5.4.320.0360.02615.24
5.4.310.0360.02715.11
5.4.300.0330.03015.24
5.4.290.0340.02715.25
5.4.280.0340.02615.26
5.4.270.0330.02815.05
5.4.260.0350.02915.25
5.4.250.0330.02815.28
5.4.240.0330.03215.26
5.4.230.0330.03215.20
5.4.220.0340.02915.19
5.4.210.0320.03115.27
5.4.200.0320.02815.27
5.4.190.0350.02715.32
5.4.180.0330.03015.12
5.4.170.0330.02815.32
5.4.160.0410.02315.20
5.4.150.0300.03015.11
5.4.140.0280.03013.78
5.4.130.0280.03213.60
5.4.120.0280.03013.75
5.4.110.0300.03113.86
5.4.100.0380.02013.94
5.4.90.0270.02913.87
5.4.80.0300.02813.94
5.4.70.0010.04013.84
5.4.60.0020.02013.86
5.4.50.0030.03013.89
5.4.40.0200.03313.69
5.4.30.0130.03313.98
5.4.20.0160.03613.71
5.4.10.0030.00911.36
5.4.00.0000.01111.37

preferences:
51.48 ms | 400 KiB | 5 Q