3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Element { const TYPE_LITERAL = 0; const TYPE_GROUP = 1; const END_OF_STRING = 2; public $type; public $value; public $next = self::END_OF_STRING; } function buildGraph($tokens) { $root = new Element; $root->type = Element::TYPE_GROUP; while ( $tokens->valid() ) { $token = $tokens->current(); $tokens->next(); switch ($token) { case '(': if ( isset($current) ) { $current->next = buildGraph($tokens); $current = $current->next; } else { $root->value[] = buildGraph($tokens); $current = end($root->value); } break; case ')': $current->next = &$root->next; return $root; case '|': $current->next = &$root->next; unset($current); break; default: if ( isset($current) ) { $current->next = new Element; $current = $current->next; } else { $root->value[] = new Element; $current = end($root->value); } $current->type = Element::TYPE_LITERAL; $current->value = $token; } } $root->next = Element::END_OF_STRING; return $root; } function getPaths($elt, $prefix = '') { if ( $elt === Element::END_OF_STRING ) { yield $prefix; return; } switch($elt->type) { case Element::TYPE_LITERAL: $prefix .= $elt->value; yield from getPaths($elt->next, $prefix); break; case Element::TYPE_GROUP: foreach ($elt->value as $value) { yield from getPaths($value, $prefix); } break; } } $pattern = 'chap(i|a) chap(o|a) p(a|i)t(a|i)p(o|a)'; // validation $validationPattern = '~ \A ( [^()]+ | \( (?1)* \) )* \z ~x'; if ( !preg_match($validationPattern, $pattern) ) throw new Exception('invalid pattern.'); // tokenization $tokens = (function ($regex) { if ( preg_match_all('~ [^()|]+ | (?<![^(|]) (?![^|)]) | [()|] ~x', $regex, $matches) ) yield from $matches[0]; })($pattern); $graph = buildGraph($tokens); foreach (getPaths($graph) as $path) { echo $path, 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.5.10.0110.00916.98
8.5.00.0160.00720.27
8.4.160.0130.01019.97
8.4.150.0010.00114.05
8.4.140.0120.00917.52
8.4.130.0110.01017.87
8.4.120.0120.00720.74
8.4.110.0080.01322.41
8.4.100.0140.00618.61
8.4.90.0150.00718.73
8.4.80.0150.00718.65
8.4.70.0050.00418.10
8.4.60.0130.01018.84
8.4.50.0110.00918.54
8.4.40.0050.00518.60
8.4.30.0070.01419.59
8.4.20.0000.00919.66
8.4.10.0170.00317.98
8.3.280.0150.00818.59
8.3.270.0160.01016.86
8.3.260.0130.00717.00
8.3.250.0110.00819.02
8.3.240.0100.01017.43
8.3.230.0130.00716.84
8.3.220.0130.00619.22
8.3.210.0120.00816.82
8.3.200.0060.00516.77
8.3.190.0140.00717.11
8.3.180.0080.00716.91
8.3.170.0100.01020.61
8.3.160.0160.00317.42
8.3.150.0000.01517.16
8.3.140.0040.01117.10
8.3.130.0000.00918.64
8.3.120.0090.00319.00
8.3.110.0060.00320.94
8.3.100.0040.00420.22
8.3.90.0090.00626.77
8.3.80.0030.00619.36
8.3.70.0120.00416.75
8.3.60.0060.01218.52
8.3.50.0110.00518.45
8.3.40.0030.01318.92
8.3.30.0110.00419.03
8.3.20.0040.00421.85
8.3.10.0040.00423.52
8.3.00.0080.00023.52
8.2.290.0070.01120.73
8.2.280.0080.00318.71
8.2.270.0090.00919.11
8.2.260.0030.00616.85
8.2.250.0000.00817.45
8.2.240.0000.00917.34
8.2.230.0080.00022.58
8.2.220.0000.00824.06
8.2.210.0080.00826.77
8.2.200.0060.00318.88
8.2.190.0100.01317.13
8.2.180.0110.00718.54
8.2.170.0150.00619.34
8.2.160.0110.00422.96
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0080.00021.25
8.2.120.0040.00426.35
8.2.110.0060.00321.04
8.2.100.0030.00918.03
8.2.90.0050.00318.20
8.2.80.0060.00318.22
8.2.70.0060.00317.88
8.2.60.0040.00417.88
8.2.50.0040.00417.93
8.2.40.0000.00919.60
8.2.30.0090.00218.26
8.2.20.0080.00018.15
8.2.10.0080.00018.22
8.2.00.0000.01218.11
8.1.330.0110.00822.08
8.1.320.0120.00916.47
8.1.310.0030.00618.46
8.1.300.0000.00916.59
8.1.290.0080.00430.84
8.1.280.0150.00425.92
8.1.270.0040.00423.82
8.1.260.0040.00426.35
8.1.250.0060.00328.09
8.1.240.0130.00020.74
8.1.230.0120.00020.91
8.1.220.0060.00318.04
8.1.210.0000.00818.96
8.1.200.0050.00317.49
8.1.190.0040.00417.60
8.1.180.0040.00418.10
8.1.170.0000.00917.70
8.1.160.0000.00718.88
8.1.150.0040.00420.82
8.1.140.0000.00717.69
8.1.130.0070.00019.09
8.1.120.0000.00717.56
8.1.110.0000.00917.68
8.1.100.0000.01017.64
8.1.90.0000.00817.67
8.1.80.0030.00617.71
8.1.70.0040.00417.58
8.1.60.0060.00317.68
8.1.50.0040.00417.73
8.1.40.0060.00617.72
8.1.30.0000.00817.82
8.1.20.0090.00017.83
8.1.10.0040.00417.77
8.1.00.0060.00317.70
8.0.300.0000.00820.11
8.0.290.0040.00417.00
8.0.280.0000.00718.51
8.0.270.0040.00417.38
8.0.260.0070.00017.39
8.0.250.0000.00817.18
8.0.240.0040.00416.98
8.0.230.0000.00717.19
8.0.220.0060.00317.07
8.0.210.0020.00516.96
8.0.200.0000.00717.04
8.0.190.0070.00017.09
8.0.180.0000.00917.13
8.0.170.0030.00717.10
8.0.160.0000.00717.10
8.0.150.0060.00317.09
8.0.140.0000.00717.10
8.0.130.0040.00413.55
8.0.120.0070.00017.09
8.0.110.0000.00717.11
8.0.100.0000.00817.15
8.0.90.0000.00817.13
8.0.80.0030.01717.11
8.0.70.0080.00017.08
8.0.60.0080.00016.98
8.0.50.0000.00717.11
8.0.30.0140.00617.37
8.0.20.0080.01617.47
8.0.10.0040.00417.16
8.0.00.0160.00317.09
7.4.330.0030.00315.55
7.4.320.0070.00016.75
7.4.300.0020.00516.85
7.4.290.0000.00716.85
7.4.280.0030.00616.87
7.4.270.0070.00016.77
7.4.260.0050.00316.83
7.4.250.0000.00716.70
7.4.240.0000.00716.79
7.4.230.0020.00516.66
7.4.220.0050.00317.01
7.4.210.0100.00716.84
7.4.200.0080.00016.73
7.4.160.0080.01216.79
7.4.140.0130.00617.86
7.4.130.0130.00716.66
7.4.120.0080.01216.71
7.4.110.0160.00316.67
7.4.100.0130.00516.82
7.4.90.0140.00616.98
7.4.80.0160.00319.39
7.4.70.0200.00416.68
7.4.60.0100.00716.75
7.4.50.0090.00516.80
7.4.40.0100.00616.71
7.4.00.0100.00714.84
7.3.330.0030.00313.39
7.3.320.0060.00013.55
7.3.310.0000.00716.67
7.3.300.0040.00416.55
7.3.290.0040.00416.44
7.3.280.0100.00616.55
7.3.260.0100.01016.84
7.3.240.0100.00916.82
7.3.230.0090.00916.76
7.3.210.0090.00916.79
7.3.200.0140.00316.93
7.3.190.0120.00616.89
7.3.180.0050.01616.53
7.3.170.0070.01016.70
7.3.160.0130.00316.64
7.3.120.0090.00615.11
7.3.110.0080.01015.04
7.3.100.0040.00915.02
7.3.90.0110.00515.12
7.3.80.0050.00914.93
7.3.70.0000.01214.96
7.3.60.0030.01215.01
7.3.50.0020.01015.09
7.3.40.0100.00314.98
7.3.30.0030.00815.04
7.3.20.0040.00616.75
7.3.10.0050.00616.65
7.3.00.0070.00616.86
7.2.330.0110.00717.01
7.2.320.0160.00916.71
7.2.310.0130.01017.04
7.2.300.0040.01516.77
7.2.290.0070.01016.97
7.2.250.0110.00715.01
7.2.240.0070.01115.14
7.2.230.0050.01115.34
7.2.220.0060.00615.38
7.2.210.0060.00915.41
7.2.200.0090.00515.31
7.2.190.0080.00615.31
7.2.180.0050.00615.28
7.2.170.0090.00615.28
7.2.160.0020.01015.17
7.2.150.0070.00317.08
7.2.140.0080.00617.12
7.2.130.0060.01016.96
7.2.120.0080.00517.16
7.2.110.0020.01617.15
7.2.100.0050.01217.16
7.2.90.0030.01117.16
7.2.80.0110.00517.17
7.2.70.0020.00916.98
7.2.60.0060.00917.22
7.2.50.0080.00717.21
7.2.40.0460.01017.70
7.2.30.0230.00917.58
7.2.20.0270.01017.44
7.2.10.0280.01017.54
7.2.00.0370.00917.34
7.1.330.0050.01016.05
7.1.320.0080.00515.78
7.1.310.0050.00915.96
7.1.300.0030.01116.13
7.1.290.0090.00215.91
7.1.280.0060.00715.81
7.1.270.0020.01115.94
7.1.260.0020.00916.04
7.1.250.0070.00916.10
7.1.200.0070.01016.02
7.1.160.0730.00917.27
7.1.150.0720.00817.14
7.1.140.0730.01217.08
7.1.130.0730.00817.22
7.1.120.0880.01417.23
7.1.110.1310.01216.48
7.1.100.1000.01316.49
7.1.90.0720.00816.80
7.1.80.0800.01116.59
7.1.70.1040.01315.62
7.1.60.0910.01633.71
7.1.50.0950.02033.01
7.1.40.1110.01733.17
7.1.30.1020.01233.05
7.1.20.0990.01433.24
7.1.10.0990.01114.98
7.1.00.0900.01514.97

preferences:
43.78 ms | 403 KiB | 5 Q