3v4l.org

run code in 300+ PHP versions simultaneously
<?php function RC($flags = ""){ return new RegCode($flags); } class RegCodeFn { public static function escape($s){ return preg_replace("/[\\/\\\\\\^\\[\\]\\.\\$\\{\\}\\*\\+\\(\\)\\|\\?\\<\\>]/", "\\\\$0", $s); } public static function compileArr($chain){ $l = count($chain); $code = ""; for ($i=0; $i < $l; $i++) { $code .= RegCodeFn::compile($chain[$i],($i + 1) < $l ? $chain[$i+1]['type'] == 'repeat' : false); } return $code; } public static function compile($item, $repeatNext){ switch ($item['type']) { case 'range': return '[' . ($item['not']?'^':'') . $item['allowed'] . ']'; break; case 'group': $res = RegCodeFn::compileArr($item['chain']); return '(' . ($item['assertion']?$item['assertion']:'') . ($item['name']?(($item['assertion']?'':'?') . 'P<' . $item['name'] . '>' ):'') . $res['code'] . ')'; break; case 'raw': case 'text': if($repeatNext && strlen($item['code']) > 1 && !(strlen($item['code']) == 2 && $item['code'][1] == '\\')){ return '(?:' . $item['code'] . ')'; }else{ return $item['code']; } break; case 'any': return "."; break; case 'end': return '$'; break; case 'start': return '^'; break; case 'repeat': return $item['code']; break; } } } class RegCode { public $flags; public $chain; public function __construct($flags = ""){ if(is_string($flags)){ $this->flags = $flags?$flags:""; }else{ $this->flags = $flags->flags; $this->chain = clone $flags->chain; } } public function start(){ $this->chain[] = array('type'=>"start"); return $this; } public function end(){ $this->chain[] = array('type'=>"end"); return $this; } public function range($allowed, $escape = true){ if($escape) $allowed = RegCodeFn::escape($allowed); $this->chain[] = array( 'type'=>'range', 'not'=>false, "allowed"=>$allowed ); return $this; } public function notRange($allowed, $escape = true){ if($escape == null) $escape = true; if($escape) $allowed = RegCodeFn::escape($allowed); $this->chain[] = array( 'type'=>'range', 'not'=>true, "allowed"=>$allowed ); return $this; } public function group($name, $assertion = null, $chain = null){ $chain = $chain == null?($assertion == null ? $name : $assertion):$chain; $assertion = is_string($assertion) ? $assertion : false; $name = is_string($name) ? $name : false; $this->chain[] = array( 'type'=>'group', 'assertion'=>$assertion, 'name'=>$name, 'chain'=>$chain->chain ); return $this; } public function any(){ $this->chain[] = array("type"=>'any'); return $this; } public function repeat($min, $max = false){ $code = ($min == '?' && $min == '*' && $min == '+')?$min:'{'.($min?$min:0) . ($max===false?'':',' . ($max?$max:'')) . '}'; $this->chain[] = array( "type"=>"repeat", "code"=>$code ); return $this; } public function raw($code){ $this->chain[] = array( "type"=>'raw', "code"=>$code ); return $this; } public function text($text,$escape){ if($escape == null) $escape = true; $this->chain[] = array( 'type'=>'text', "code"=>$escape?RegCodeFn::escape($text):$text ); return $this; } public function __toString(){ return "/" . RegCodeFn::compileArr($this->chain) . "/" . $this->flags; } public function compile(){ return new RegCodeCompiled(RegCodeFn::compileArr($this->chain), $this->flags); } } class RegCodeCompiled { public $code; public $flags; public function __construct($code, $flags){ $this->code = $code; $this->flags = $flags; } public function match($subject, &$matches = null, $flags = 0, $offset = 0){ return preg_match("/" . $this->code . "/" . $this->flags, $subject, $matches, $flags, $offset); } public function match_all(){ } public function replace($replacement, $subject, $limit = -1, &$count = null){ return preg_replace("/" . $this->code . "/" . $this->flags, $replacement, $subject, $limit, $count); } public function replace_callback($callback, $subject, $limit = -1, &$count = null){ return preg_replace_callback("/" . $this->code . "/" . $this->flags, $callback, $subject, $limit, $count); } } $match; RC() ->start() ->range('a-z') ->range('a-z0-9')->repeat(3,null) ->end()->compile()->match("all3tho",$match); var_dump($match);

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.0100.01018.43
8.3.50.0050.01221.33
8.3.40.0030.01219.31
8.3.30.0180.00319.29
8.3.20.0050.00320.59
8.3.10.0000.00822.09
8.3.00.0000.00820.89
8.2.180.0070.00716.63
8.2.170.0060.00922.96
8.2.160.0060.01019.51
8.2.150.0060.00324.18
8.2.140.0050.00324.66
8.2.130.0050.00326.16
8.2.120.0040.00419.89
8.2.110.0060.00322.20
8.2.100.0040.00819.88
8.2.90.0030.00519.36
8.2.80.0050.00318.04
8.2.70.0040.00418.00
8.2.60.0000.00818.05
8.2.50.0050.00318.07
8.2.40.0030.00619.95
8.2.30.0040.00718.14
8.2.20.0000.00817.89
8.2.10.0040.00418.04
8.2.00.0040.00418.00
8.1.280.0070.01125.92
8.1.270.0050.00322.23
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0030.00723.84
8.1.230.0080.00419.30
8.1.220.0040.00417.91
8.1.210.0040.00418.77
8.1.200.0000.00917.60
8.1.190.0000.00817.53
8.1.180.0080.00018.77
8.1.170.0040.00418.99
8.1.160.0030.00522.17
8.1.150.0000.00818.88
8.1.140.0100.00017.70
8.1.130.0000.00717.79
8.1.120.0050.00317.70
8.1.110.0110.00017.70
8.1.100.0060.00317.57
8.1.90.0050.00317.60
8.1.80.0000.00717.69
8.1.70.0030.00317.54
8.1.60.0040.00417.79
8.1.50.0030.00517.66
8.1.40.0030.00617.77
8.1.30.0000.00817.85
8.1.20.0050.00317.89
8.1.10.0030.00517.73
8.1.00.0080.00017.68
8.0.300.0040.00418.77
8.0.290.0030.00617.18
8.0.280.0000.00818.43
8.0.270.0070.00317.31
8.0.260.0040.00417.02
8.0.250.0070.00017.25
8.0.240.0090.00017.23
8.0.230.0040.00417.18
8.0.220.0000.00717.03
8.0.210.0000.00717.08
8.0.200.0000.00717.05
8.0.190.0030.00617.10
8.0.180.0000.00717.08
8.0.170.0050.00317.08
8.0.160.0050.00317.15
8.0.150.0040.00817.14
8.0.140.0000.00817.12
8.0.130.0000.00613.65
8.0.120.0060.00316.99
8.0.110.0040.00417.07
8.0.100.0030.00516.96
8.0.90.0000.00817.12
8.0.80.0130.00317.19
8.0.70.0080.00017.15
8.0.60.0040.00417.12
8.0.50.0080.00017.00
8.0.30.0110.01017.33
8.0.20.0140.00517.53
8.0.10.0030.00617.13
8.0.00.0100.00816.92
7.4.330.0030.00315.10
7.4.320.0000.00616.82
7.4.300.0040.00416.77
7.4.290.0000.00816.71
7.4.280.0040.00416.71
7.4.270.0040.00416.91
7.4.260.0050.00516.75
7.4.250.0030.00516.85
7.4.240.0040.00416.85
7.4.230.0060.00316.95
7.4.220.0090.01316.93
7.4.210.0040.01116.91
7.4.200.0000.00716.65
7.4.190.0030.00516.79
7.4.160.0160.00016.89
7.4.150.0070.01117.40
7.4.140.0110.01017.86
7.4.130.0110.00916.81
7.4.120.0090.00916.82
7.4.110.0110.00816.73
7.4.100.0090.00916.77
7.4.90.0110.00716.77
7.4.80.0110.00919.39
7.4.70.0060.01316.74
7.4.60.0040.01516.65
7.4.50.0030.00316.59
7.4.40.0060.01322.77
7.4.30.0140.00416.86
7.4.00.0040.00715.03
7.3.330.0000.00513.46
7.3.320.0000.00613.60
7.3.310.0000.00816.48
7.3.300.0030.00316.57
7.3.290.0100.00716.63
7.3.280.0080.01116.62
7.3.270.0090.00917.40
7.3.260.0060.01916.65
7.3.250.0090.00916.96
7.3.240.0130.00916.94
7.3.230.0080.01216.80
7.3.210.0060.01016.58
7.3.200.0090.00919.39
7.3.190.0210.04216.85
7.3.180.0120.00416.70
7.3.170.0060.01716.80
7.3.160.0120.00416.95
7.3.120.0070.00715.32
7.3.10.0060.01016.71
7.3.00.0000.01216.84
7.2.330.0130.00717.01
7.2.320.0150.00616.95
7.2.310.0130.00416.98
7.2.300.0040.01517.11
7.2.290.0070.01017.07
7.2.130.0060.01016.99
7.2.120.0070.00717.26
7.2.110.0030.00717.17
7.2.100.0080.00817.17
7.2.90.0000.01616.92
7.2.80.0040.01217.06
7.2.70.0120.00017.42
7.2.60.0000.01117.12
7.2.50.0100.00617.26
7.2.40.0090.00617.13
7.2.30.0070.00716.98
7.2.20.0040.00817.29
7.2.10.0040.01217.13
7.2.00.0050.00918.52
7.1.250.0030.01015.91
7.1.100.0070.01018.42
7.1.70.0030.00617.50
7.1.60.0120.01219.82
7.1.50.0030.01017.20
7.1.00.0030.07722.35
7.0.200.0110.01116.61
7.0.140.0100.07021.98
7.0.100.0100.06720.07
7.0.90.0100.07320.21
7.0.80.0170.05720.02
7.0.70.0130.06320.05
7.0.60.0070.08020.00
7.0.50.0100.08020.29
7.0.40.0130.07319.96
7.0.30.0130.07320.11
7.0.20.0070.08320.09
7.0.10.0100.05020.04
7.0.00.0100.07020.02
5.6.280.0070.07021.13
5.6.250.0170.07320.64
5.6.240.0070.05320.72
5.6.230.0030.08320.62
5.6.220.0070.08020.53
5.6.210.0100.04720.74
5.6.200.0070.04021.09
5.6.190.0200.05721.14
5.6.180.0030.07721.19
5.6.170.0130.08021.10
5.6.160.0100.08021.22
5.6.150.0030.05321.13
5.6.140.0070.06721.05
5.6.130.0100.08021.04
5.6.120.0130.07721.14
5.6.110.0070.07721.06
5.6.100.0070.07321.07
5.6.90.0070.09021.07
5.6.80.0070.08020.55
5.6.70.0130.07020.39
5.6.60.0130.05320.46
5.6.50.0100.08320.38
5.6.40.0000.05720.45
5.6.30.0100.07720.47
5.6.20.0070.08320.57
5.6.10.0070.05020.41
5.6.00.0070.07720.42
5.5.380.0200.07320.47
5.5.370.0070.08020.37
5.5.360.0100.06720.41
5.5.350.0170.07320.54
5.5.340.0030.06020.92
5.5.330.0100.06720.95
5.5.320.0100.07320.92
5.5.310.0070.08320.83
5.5.300.0100.07020.81
5.5.290.0070.07720.91
5.5.280.0200.07020.70
5.5.270.0130.08020.88
5.5.260.0170.07720.95
5.5.250.0130.05720.74
5.5.240.0100.07020.33
5.5.230.0000.06320.24
5.5.220.0070.06720.23
5.5.210.0030.08320.21
5.5.200.0030.07320.23
5.5.190.0100.08020.33
5.5.180.0130.07320.28
5.5.160.0100.08020.26
5.5.150.0100.08720.30
5.5.140.0070.07720.24
5.5.130.0070.08020.29
5.5.120.0100.04320.26
5.5.110.0000.08320.13
5.5.100.0030.08720.21
5.5.90.0170.06320.21
5.5.80.0100.07720.14
5.5.70.0130.07720.14
5.5.60.0030.07720.11
5.5.50.0100.07020.12
5.5.40.0100.07020.11
5.5.30.0130.07020.15
5.5.20.0070.05020.20
5.5.10.0030.08020.18
5.5.00.0070.04020.07
5.4.450.0130.08019.46
5.4.440.0030.08719.35
5.4.430.0000.08719.20
5.4.420.0170.04719.44
5.4.410.0000.08719.14
5.4.400.0070.07318.85
5.4.390.0070.07718.88
5.4.380.0030.04719.03
5.4.370.0030.08019.05
5.4.360.0070.08019.13
5.4.350.0100.07718.96
5.4.340.0100.07019.23
5.4.320.0030.08019.13
5.4.310.0200.07018.88
5.4.300.0030.06719.16
5.4.290.0200.06718.90
5.4.280.0100.07718.95
5.4.270.0070.07318.94
5.4.260.0030.07319.09
5.4.250.0130.07019.20
5.4.240.0070.04719.04
5.4.230.0100.08019.04
5.4.220.0030.04719.05
5.4.210.0100.07018.91
5.4.200.0100.06719.17
5.4.190.0130.06719.11
5.4.180.0030.03719.24
5.4.170.0070.06719.11
5.4.160.0070.07319.02
5.4.150.0130.06719.01
5.4.140.0030.07716.50
5.4.130.0100.06016.46
5.4.120.0070.03016.48
5.4.110.0070.06016.52
5.4.100.0100.06716.55
5.4.90.0030.03316.33
5.4.80.0030.07316.53
5.4.70.0170.06316.39
5.4.60.0030.08016.38
5.4.50.0100.07316.54
5.4.40.0070.07016.39
5.4.30.0070.06716.36
5.4.20.0030.08016.49
5.4.10.0030.05016.51
5.4.00.0100.04015.93
5.3.290.0030.06314.75
5.3.280.0170.08314.76
5.3.270.0030.04314.75
5.3.260.0070.08014.67
5.3.250.0000.06314.74
5.3.240.0030.08014.66
5.3.230.0070.07714.68
5.3.220.0030.07714.62
5.3.210.0030.07014.61
5.3.200.0070.04014.65
5.3.190.0030.08314.57
5.3.180.0100.07314.61
5.3.170.0030.06714.75
5.3.160.0100.07014.62
5.3.150.0100.08014.63
5.3.140.0000.06314.74
5.3.130.0030.09314.71
5.3.120.0170.06314.60
5.3.110.0130.07014.54
5.3.100.0030.07714.16
5.3.90.0030.07314.11
5.3.80.0100.07013.98
5.3.70.0030.08014.10
5.3.60.0100.07013.98
5.3.50.0170.05714.14
5.3.40.0070.07714.13
5.3.30.0030.08013.91
5.3.20.0000.06313.83
5.3.10.0070.07713.76
5.3.00.0130.06713.64

preferences:
38.5 ms | 401 KiB | 5 Q