3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = <<<'STR' Group test { Group test1 { #-# Type Val 1 typ1 10 2 typ2 10 3 typ3 10 } Group test2 { #-# Type Val 1 typ1 10 2 typ2 10 } } STR; $pattern = <<<'REGEX' ~ (?(DEFINE) (?<group> Group \s+ \g<groupName> \s* { \s* (?: \g<group> (?: \s+ \g<group>)* | \g<line> (?: \h*+ \s+ \g<line> )* )? \s* } ) (?<groupName> \w+ ) (?<line> \g<value> (?: \h+ \g<value>)* ) (?<value> [^\s{}]+ ) ) \A \s* \g<group> \s* \z (*:MAIN_GROUP) ~x REGEX; function group2array($group) { $ret = []; $index = 0; // this pattern extracts the group name and the group content preg_match( '~Group \s+ (?<name> \w+ ) \s* { \s* (?<content> .* \S ) \s* } ~sx', $group, $match ); $name = $match['name']; $content = $match['content']; $ret[$name] = []; preg_match_all( // this one extracts groups or lines of values '~ \s* (?<group> Group \s+ \w+ \s* { [^{}]*+ (?: \g<group> [^{}]* )*+ } ) | \s* (?<line> [^\s{}]+ (?: \h+ [^\s{}]+ )* ) ~x', $content, $matches, PREG_SET_ORDER ); foreach($matches as $m) { if (isset($m['line'])) { $ret[$name][$index++] = preg_split('~\s+~', $m['line']); } else { $group = group2array($m['group']); $ret[$name][key($group)] = current($group); } } return $ret; } if ( preg_match($pattern, $str) ) { // check the string syntax before parsing $result = group2array($str); echo json_encode($result), PHP_EOL, print_r($result, true), PHP_EOL; }

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.0030.01317.00
8.3.60.0130.01018.43
8.3.50.0000.01518.57
8.3.40.0150.00619.02
8.3.30.0120.00319.21
8.3.20.0040.00424.18
8.3.10.0060.00324.66
8.3.00.0040.00426.16
8.2.190.0090.00917.13
8.2.180.0040.01825.92
8.2.170.0030.01319.20
8.2.160.0070.00722.96
8.2.150.0000.00725.66
8.2.140.0050.00324.66
8.2.130.0050.00326.16
8.2.120.0080.00021.07
8.2.110.0040.00420.52
8.2.100.0040.01117.91
8.2.90.0030.00517.75
8.2.80.0070.00318.86
8.2.70.0000.00817.88
8.2.60.0040.00417.75
8.2.50.0050.00317.88
8.2.40.0060.00318.28
8.2.30.0030.00518.05
8.2.20.0000.00820.64
8.2.10.0040.00418.20
8.2.00.0030.00819.43
8.1.280.0040.01125.92
8.1.270.0110.00723.89
8.1.260.0110.00026.35
8.1.250.0040.00428.09
8.1.240.0100.00019.12
8.1.230.0090.00322.25
8.1.220.0050.00317.74
8.1.210.0040.00418.77
8.1.200.0000.00917.60
8.1.190.0030.00617.48
8.1.180.0030.00618.10
8.1.170.0040.00418.90
8.1.160.0070.00018.95
8.1.150.0090.00018.83
8.1.140.0040.00417.67
8.1.130.0000.00717.55
8.1.120.0000.00717.64
8.1.110.0060.00317.57
8.1.100.0040.00417.64
8.1.90.0030.00517.52
8.1.80.0080.00017.61
8.1.70.0070.00017.52
8.1.60.0000.00817.80
8.1.50.0190.00517.59
8.1.40.0080.00417.70
8.1.30.0080.00817.76
8.1.20.0150.00917.79
8.1.10.0170.00217.61
8.1.00.0230.00017.69
8.0.300.0050.00318.77
8.0.290.0000.00817.00
8.0.280.0000.00918.49
8.0.270.0030.00518.25
8.0.260.0050.00217.12
8.0.250.0000.00717.23
8.0.240.0000.00717.10
8.0.230.0030.00417.07
8.0.220.0000.00717.04
8.0.210.0050.00317.05
8.0.200.0050.00317.21
8.0.190.0040.00417.09
8.0.180.0160.00317.03
8.0.170.0070.00317.13
8.0.160.0080.00817.11
8.0.150.0110.00716.95
8.0.140.0160.00317.12
8.0.130.0120.00817.13
8.0.120.0150.00417.00
8.0.110.0140.00317.10
8.0.100.0140.00617.16
8.0.90.0170.00317.07
8.0.80.0160.00516.97
8.0.70.0190.00016.94
8.0.60.0080.00517.11
8.0.50.0110.00316.91
8.0.30.0150.00217.00
8.0.20.0170.00317.09
8.0.10.0050.00917.11
7.4.330.0060.00015.55
7.4.320.0030.00316.84
7.4.300.0060.00016.89
7.4.290.0050.00516.67
7.4.280.0030.00616.89
7.4.270.0060.00316.85
7.4.260.0150.00316.66
7.4.250.0090.00916.76
7.4.240.0120.00816.85
7.4.230.0150.00516.66
7.4.220.0130.00716.82
7.4.210.0100.01016.79
7.4.200.0150.00316.79
7.4.190.0120.00616.85
7.4.180.0090.00916.80
7.4.160.0150.00416.87
7.4.150.0150.00316.83
7.4.140.0070.00716.75
7.4.130.0140.00316.84
7.4.120.0160.00016.75
7.4.110.0150.00316.81
7.4.100.0160.00316.89
7.4.90.0160.00416.69
7.4.80.0100.00916.73
7.4.70.0140.00316.82
7.4.60.0100.00716.76
7.4.50.0150.00316.68
7.4.40.0160.00316.77
7.4.30.0110.00716.74
7.4.20.0120.00616.73
7.4.10.0110.00716.72
7.4.00.0140.00016.76

preferences:
58.07 ms | 401 KiB | 5 Q