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($force){ 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); } } echo RC() ->start() ->range('a-z') ->range('a-z0-9')->repeat(3,null) ->end()->match("all3");

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.0070.01418.80
8.3.50.0140.00721.21
8.3.40.0090.00619.21
8.3.30.0110.00719.17
8.3.20.0040.00420.30
8.3.10.0080.00022.04
8.3.00.0040.00420.86
8.2.180.0130.01017.00
8.2.170.0120.00322.96
8.2.160.0130.01019.33
8.2.150.0040.00424.18
8.2.140.0060.00324.66
8.2.130.0160.00326.16
8.2.120.0000.00819.86
8.2.110.0030.00622.11
8.2.100.0120.00020.01
8.2.90.0030.00619.32
8.2.80.0030.00518.05
8.2.70.0060.00318.13
8.2.60.0040.00418.05
8.2.50.0040.00418.07
8.2.40.0040.00420.07
8.2.30.0050.00318.25
8.2.20.0000.00817.93
8.2.10.0000.00818.00
8.2.00.0080.00017.96
8.1.280.0210.00025.92
8.1.270.0040.00422.30
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0030.00623.87
8.1.230.0040.00719.22
8.1.220.0030.00517.91
8.1.210.0000.00918.77
8.1.200.0090.00017.60
8.1.190.0050.00317.78
8.1.180.0030.00618.92
8.1.170.0040.00418.92
8.1.160.0000.00722.24
8.1.150.0030.00518.92
8.1.140.0060.00317.61
8.1.130.0050.00217.90
8.1.120.0040.00417.63
8.1.110.0000.01117.73
8.1.100.0060.00317.70
8.1.90.0080.00017.60
8.1.80.0000.00817.68
8.1.70.0040.00417.65
8.1.60.0000.00817.84
8.1.50.0030.00517.63
8.1.40.0080.00017.69
8.1.30.0040.00417.87
8.1.20.0040.00417.79
8.1.10.0030.00617.71
8.1.00.0000.00917.64
8.0.300.0000.00718.77
8.0.290.0080.00017.18
8.0.280.0080.00018.56
8.0.270.0000.00817.37
8.0.260.0050.00317.15
8.0.250.0030.00317.16
8.0.240.0000.00917.26
8.0.230.0080.00017.28
8.0.220.0000.00717.11
8.0.210.0050.00217.21
8.0.200.0000.00717.24
8.0.190.0000.01117.25
8.0.180.0050.00317.07
8.0.170.0050.00217.16
8.0.160.0000.00717.25
8.0.150.0090.00017.09
8.0.140.0090.00017.06
8.0.130.0060.00013.61
8.0.120.0030.00617.14
8.0.110.0050.00217.12
8.0.100.0040.00417.14
8.0.90.0000.00817.21
8.0.80.0080.01617.18
8.0.70.0030.00617.09
8.0.60.0040.00417.25
8.0.50.0030.00517.04
8.0.30.0120.00617.25
8.0.20.0100.00917.42
8.0.10.0000.00817.27
8.0.00.0090.00917.06
7.4.330.0030.00315.18
7.4.320.0040.00416.81
7.4.300.0070.00316.80
7.4.290.0030.00316.81
7.4.280.0000.00716.93
7.4.270.0040.00416.83
7.4.260.0030.00716.69
7.4.250.0080.00016.73
7.4.240.0020.00616.86
7.4.230.0050.00316.66
7.4.220.0100.00716.97
7.4.210.0080.00716.81
7.4.200.0070.00016.66
7.4.190.0030.00317.05
7.4.160.0050.01116.82
7.4.150.0060.01217.40
7.4.140.0120.00617.86
7.4.130.0030.01516.73
7.4.120.0130.00616.84
7.4.110.0070.01116.58
7.4.100.0130.00316.81
7.4.90.0130.00616.79
7.4.80.0000.02419.39
7.4.70.0060.01216.66
7.4.60.0070.01016.91
7.4.50.0090.00016.63
7.4.40.0000.01622.77
7.4.30.0070.01016.86
7.4.00.0030.01315.30
7.3.330.0050.00013.48
7.3.320.0030.00313.66
7.3.310.0000.00716.61
7.3.300.0050.00216.72
7.3.290.0110.00916.68
7.3.280.0100.01116.63
7.3.270.0120.00617.40
7.3.260.0110.01116.94
7.3.250.0090.01116.82
7.3.240.0030.01716.86
7.3.230.0060.01116.71
7.3.210.0140.00416.70
7.3.200.0140.00319.39
7.3.190.0030.01516.64
7.3.180.0060.01116.67
7.3.170.0130.00316.63
7.3.160.0110.00516.82
7.3.120.0040.01415.26
7.3.110.0080.01215.30
7.3.100.0060.00915.24
7.3.90.0040.00415.00
7.3.80.0070.01014.93
7.3.70.0040.01115.07
7.3.60.0060.00615.23
7.3.50.0070.00315.12
7.3.40.0090.00415.06
7.3.30.0100.01015.15
7.3.20.0070.00716.88
7.3.10.0160.00316.69
7.3.00.0060.00916.91
7.2.330.0070.01316.77
7.2.320.0120.00616.95
7.2.310.0170.00017.04
7.2.300.0000.01716.76
7.2.290.0060.00917.02
7.2.250.0060.01215.10
7.2.240.0070.01415.17
7.2.230.0040.00415.36
7.2.220.0110.00315.38
7.2.210.0000.01115.18
7.2.200.0100.00015.30
7.2.190.0110.00715.34
7.2.180.0090.00615.20
7.2.170.0070.00315.11
7.2.60.0030.01217.26
7.2.00.0000.01619.79
7.1.330.0080.00316.17
7.1.320.0170.00015.86
7.1.310.0030.00715.96
7.1.300.0070.00315.84
7.1.290.0100.00315.97
7.1.280.0060.00915.81
7.1.270.0100.01015.83
7.1.260.0060.01215.83
7.1.200.0030.00716.05
7.1.100.0070.01018.09
7.1.70.0030.00917.45
7.1.60.0100.01319.82
7.1.50.0070.00416.98
7.1.00.0000.07722.38
7.0.200.0140.00716.72
7.0.140.0130.06322.01
7.0.100.0300.08020.11
7.0.90.0070.04720.08
7.0.80.0170.08320.00
7.0.70.0100.08019.96
7.0.60.0000.05319.96
7.0.50.0100.08020.46
7.0.40.0100.08319.95
7.0.30.0070.07320.04
7.0.20.0070.05320.09
7.0.10.0030.04720.10
7.0.00.0070.05020.18
5.6.280.0030.07321.20
5.6.250.0100.05720.65
5.6.240.0100.08020.57
5.6.230.0070.08320.69
5.6.220.0100.07320.64
5.6.210.0070.07020.80
5.6.200.0030.07021.12
5.6.190.0100.06720.96
5.6.180.0100.08321.07
5.6.170.0100.06321.09
5.6.160.0100.06721.01
5.6.150.0130.08321.11
5.6.140.0070.05021.14
5.6.130.0130.08021.12
5.6.120.0200.06721.16
5.6.110.0100.06720.99
5.6.100.0000.04321.18
5.6.90.0070.07020.97
5.6.80.0000.06720.61
5.6.70.0100.05720.61
5.6.60.0130.06720.37
5.6.50.0100.07020.46
5.6.40.0100.04020.52
5.6.30.0000.07720.46
5.6.20.0200.06720.52
5.6.10.0130.07720.57
5.6.00.0170.05320.48
5.5.380.0170.04020.57
5.5.370.0100.08320.45
5.5.360.0100.05020.43
5.5.350.0130.07020.40
5.5.340.0000.04720.87
5.5.330.0200.07320.79
5.5.320.0030.07020.99
5.5.310.0070.08320.82
5.5.300.0000.09020.93
5.5.290.0100.06720.94
5.5.280.0170.05020.98
5.5.270.0030.05320.91
5.5.260.0000.05020.95
5.5.250.0030.04020.68
5.5.240.0070.06320.34
5.5.230.0100.07720.07
5.5.220.0030.08020.23
5.5.210.0000.07020.34
5.5.200.0030.07320.34
5.5.190.0030.07320.35
5.5.180.0130.08020.17
5.5.160.0130.06320.16
5.5.150.0070.04320.27
5.5.140.0030.07320.18
5.5.130.0030.08720.16
5.5.120.0070.07320.32
5.5.110.0030.06720.32
5.5.100.0070.04020.14
5.5.90.0100.07720.22
5.5.80.0070.05320.17
5.5.70.0070.07720.16
5.5.60.0070.04020.21
5.5.50.0170.06019.98
5.5.40.0100.05019.99
5.5.30.0030.07720.23
5.5.20.0070.04020.22
5.5.10.0070.07020.14
5.5.00.0030.08020.10
5.4.450.0070.06319.21
5.4.440.0070.07719.27
5.4.430.0100.06019.46
5.4.420.0100.06019.27
5.4.410.0200.02019.29
5.4.400.0070.03319.05
5.4.390.0030.06019.23
5.4.380.0030.06319.05
5.4.370.0030.04719.04
5.4.360.0070.05719.21
5.4.350.0100.07318.91
5.4.340.0130.06018.88
5.4.320.0030.04319.19
5.4.310.0130.06719.09
5.4.300.0070.07319.04
5.4.290.0070.06019.04
5.4.280.0070.06019.04
5.4.270.0200.05319.02
5.4.260.0130.06319.05
5.4.250.0100.07019.04
5.4.240.0130.06019.09
5.4.230.0130.06719.04
5.4.220.0000.07319.09
5.4.210.0100.07319.12
5.4.200.0070.06019.18
5.4.190.0030.08318.94
5.4.180.0030.07319.20
5.4.170.0070.07718.84
5.4.160.0000.07019.07
5.4.150.0130.03719.16
5.4.140.0030.07016.52
5.4.130.0130.04016.55
5.4.120.0100.07016.30
5.4.110.0100.07016.42
5.4.100.0100.06716.42
5.4.90.0000.05016.56
5.4.80.0070.06716.37
5.4.70.0100.07016.38
5.4.60.0070.07016.43
5.4.50.0100.07316.43
5.4.40.0100.06716.53
5.4.30.0100.07016.54
5.4.20.0070.03316.50
5.4.10.0030.04016.56
5.4.00.0100.07016.00
5.3.290.0100.03714.80
5.3.280.0100.04014.63
5.3.270.0030.04314.75
5.3.260.0100.04314.58
5.3.250.0030.07314.66
5.3.240.0000.08714.75
5.3.230.0130.05714.63
5.3.220.0130.06714.62
5.3.210.0030.06314.71
5.3.200.0100.06714.63
5.3.190.0100.07014.73
5.3.180.0070.05014.60
5.3.170.0130.06714.78
5.3.160.0070.07314.68
5.3.150.0130.07014.63
5.3.140.0070.07314.61
5.3.130.0030.07014.74
5.3.120.0000.06314.58
5.3.110.0000.08014.66
5.3.100.0030.07714.14
5.3.90.0070.04314.21
5.3.80.0070.06314.00
5.3.70.0030.04314.13
5.3.60.0130.06314.13
5.3.50.0130.06314.06
5.3.40.0000.08314.14
5.3.30.0100.07313.96
5.3.20.0000.05013.69
5.3.10.0030.04713.83
5.3.00.0130.06313.71

preferences:
42.36 ms | 401 KiB | 5 Q