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); } } echo RC() ->start() ->range('a-z') ->range('a-z0-9')->repeat(3,null) ->end()->compile()->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.0140.00718.80
8.3.50.0110.00821.34
8.3.40.0070.00718.92
8.3.30.0070.01319.14
8.3.20.0040.00420.32
8.3.10.0050.00322.10
8.3.00.0090.00020.71
8.2.180.0110.00417.00
8.2.170.0070.01422.96
8.2.160.0170.00319.46
8.2.150.0040.00424.18
8.2.140.0030.00624.66
8.2.130.0070.01326.16
8.2.120.0060.00319.61
8.2.110.0040.00422.29
8.2.100.0070.00419.76
8.2.90.0040.00419.30
8.2.80.0080.00018.16
8.2.70.0060.00318.00
8.2.60.0040.00418.05
8.2.50.0040.00418.07
8.2.40.0040.00419.88
8.2.30.0080.00018.15
8.2.20.0040.00417.95
8.2.10.0030.00517.89
8.2.00.0060.00317.97
8.1.280.0140.00725.92
8.1.270.0040.00422.12
8.1.260.0050.00326.35
8.1.250.0030.00628.09
8.1.240.0100.00023.96
8.1.230.0060.00619.27
8.1.220.0040.00417.91
8.1.210.0040.00418.77
8.1.200.0030.00717.60
8.1.190.0040.00417.64
8.1.180.0030.00618.95
8.1.170.0040.00418.69
8.1.160.0070.00022.26
8.1.150.0040.00418.93
8.1.140.0080.00017.59
8.1.130.0000.00717.90
8.1.120.0040.00417.63
8.1.110.0030.00717.60
8.1.100.0040.00417.74
8.1.90.0000.00817.72
8.1.80.0030.00617.52
8.1.70.0030.00317.57
8.1.60.0030.00517.89
8.1.50.0080.00017.82
8.1.40.0080.00017.73
8.1.30.0040.00417.77
8.1.20.0030.00517.88
8.1.10.0000.00817.71
8.1.00.0000.00917.65
8.0.300.0000.00718.77
8.0.290.0000.00817.30
8.0.280.0040.00418.43
8.0.270.0040.00416.93
8.0.260.0030.00316.97
8.0.250.0040.00417.18
8.0.240.0040.00417.20
8.0.230.0040.00417.08
8.0.220.0000.00717.05
8.0.210.0000.00717.14
8.0.200.0000.00717.17
8.0.190.0040.00417.11
8.0.180.0050.00217.08
8.0.170.0040.00417.13
8.0.160.0080.00017.11
8.0.150.0060.00317.14
8.0.140.0040.00417.09
8.0.130.0000.00713.52
8.0.120.0040.00417.02
8.0.110.0000.00817.20
8.0.100.0040.00417.08
8.0.90.0050.00216.95
8.0.80.0130.01017.07
8.0.70.0030.00517.13
8.0.60.0080.00017.00
8.0.50.0040.00416.96
8.0.30.0120.00917.33
8.0.20.0080.01017.56
8.0.10.0030.00517.16
8.0.00.0080.01117.08
7.4.330.0000.00515.00
7.4.320.0000.00716.80
7.4.300.0040.00416.66
7.4.290.0030.00516.83
7.4.280.0050.00316.83
7.4.270.0030.00316.90
7.4.260.0040.00416.83
7.4.250.0030.00516.70
7.4.240.0020.00616.83
7.4.230.0040.00416.56
7.4.220.0100.01016.87
7.4.210.0070.01016.84
7.4.200.0040.00416.94
7.4.190.0040.00416.87
7.4.160.0040.01217.05
7.4.150.0160.00917.40
7.4.140.0140.01017.86
7.4.130.0130.00516.82
7.4.120.0100.01116.82
7.4.110.0030.01516.82
7.4.100.0030.01416.85
7.4.90.0100.00716.70
7.4.80.0000.02319.39
7.4.70.0130.00516.82
7.4.60.0090.01116.89
7.4.50.0040.00416.89
7.4.40.0030.00922.77
7.4.30.0180.00016.77
7.4.10.0060.01215.16
7.4.00.0080.00815.29
7.3.330.0000.00513.57
7.3.320.0000.00513.52
7.3.310.0050.00216.47
7.3.300.0080.00016.56
7.3.290.0090.00616.66
7.3.280.0090.00816.59
7.3.270.0170.00717.40
7.3.260.0070.01416.63
7.3.250.0110.01016.75
7.3.240.0000.02116.53
7.3.230.0070.01016.95
7.3.210.0120.00616.86
7.3.200.0030.01319.39
7.3.190.0090.00916.84
7.3.180.0060.01016.83
7.3.170.0080.00816.66
7.3.160.0060.00916.89
7.3.130.0070.01015.02
7.3.120.0020.01615.23
7.3.110.0040.01515.44
7.3.100.0040.01115.32
7.3.90.0040.01115.04
7.3.80.0000.01315.22
7.3.70.0060.00914.96
7.3.60.0060.00615.18
7.3.50.0080.00514.97
7.3.40.0040.01115.13
7.3.30.0040.00815.18
7.3.20.0070.01016.78
7.3.10.0100.00016.91
7.3.00.0090.00616.66
7.2.330.0120.00616.90
7.2.320.0060.01016.89
7.2.310.0120.01216.76
7.2.300.0040.01316.94
7.2.290.0080.00816.87
7.2.260.0110.00815.36
7.2.250.0090.00715.25
7.2.240.0000.01515.38
7.2.230.0000.00915.34
7.2.220.0040.01515.57
7.2.210.0000.01415.39
7.2.200.0030.00615.31
7.2.190.0070.00715.41
7.2.180.0040.00415.60
7.2.170.0040.01015.40
7.2.160.0130.00315.22
7.2.150.0070.00717.08
7.2.140.0070.00317.18
7.2.130.0060.00617.23
7.2.120.0030.00917.21
7.2.110.0000.01417.21
7.2.100.0060.00917.00
7.2.90.0060.00616.99
7.2.80.0060.00617.12
7.2.70.0070.01017.22
7.2.60.0070.00717.19
7.2.50.0030.01317.15
7.2.40.0070.00717.11
7.2.30.0040.01117.30
7.2.20.0090.00316.89
7.2.10.0100.00717.16
7.2.00.0000.01517.13
7.1.330.0030.01016.02
7.1.320.0040.01116.07
7.1.310.0030.01015.73
7.1.300.0030.00615.98
7.1.290.0070.00715.93
7.1.280.0110.00315.99
7.1.270.0040.00815.97
7.1.260.0100.00716.08
7.1.250.0000.01416.04
7.1.240.0030.01016.02
7.1.230.0090.00615.70
7.1.220.0060.00916.12
7.1.210.0070.00716.18
7.1.200.0030.01215.93
7.1.190.0090.00615.85
7.1.180.0030.00716.14
7.1.170.0090.00315.99
7.1.160.0000.01215.92
7.1.150.0040.00716.18
7.1.140.0000.01015.96
7.1.130.0060.00615.75
7.1.120.0030.01016.07
7.1.110.0070.00716.16
7.1.100.0030.00915.87
7.1.90.0030.01015.83
7.1.80.0000.01715.88
7.1.70.0000.01016.60
7.1.60.0050.01217.99
7.1.50.0050.01016.63
7.1.40.0070.00716.02
7.1.30.0060.00315.71
7.1.20.0030.00615.76
7.1.10.0030.00616.08
7.1.00.0120.03219.34
7.0.330.0040.00415.73
7.0.320.0070.00715.68
7.0.310.0000.01015.55
7.0.300.0070.00715.71
7.0.290.0050.00515.50
7.0.280.0040.00715.41
7.0.270.0090.00315.56
7.0.260.0060.00915.51
7.0.250.0070.00715.52
7.0.240.0000.01215.73
7.0.230.0100.00015.64
7.0.220.0140.00315.76
7.0.210.0060.00615.70
7.0.200.0110.00716.13
7.0.190.0040.01115.74
7.0.180.0040.00815.36
7.0.170.0040.00715.44
7.0.160.0030.01015.56
7.0.150.0090.00615.51
7.0.140.0060.03718.67
7.0.130.0110.00415.75
7.0.120.0070.00715.78
7.0.110.0030.01415.68
7.0.100.0030.03217.72
7.0.90.0140.04017.63
7.0.80.0120.02717.78
7.0.70.0090.04417.66
7.0.60.0070.02917.83
7.0.50.0080.02518.02
7.0.40.0060.04516.96
7.0.30.0050.03316.91
7.0.20.0100.01816.76
7.0.10.0070.04016.69
7.0.00.0040.03016.92
5.6.400.0030.00714.64
5.6.390.0000.01614.59
5.6.380.0040.00814.29
5.6.370.0060.00314.49
5.6.360.0070.00714.57
5.6.350.0050.00814.59
5.6.340.0090.00614.96
5.6.330.0090.00314.53
5.6.320.0040.00814.80
5.6.310.0060.01014.85
5.6.300.0030.01314.88
5.6.290.0070.00314.58
5.6.280.0050.04217.82
5.6.270.0060.00914.74
5.6.260.0030.00914.69
5.6.250.0030.03517.70
5.6.240.0090.03317.68
5.6.230.0120.03617.67
5.6.220.0050.04917.48
5.6.210.0070.03217.63
5.6.200.0080.03217.91
5.6.190.0020.05017.87
5.6.180.0080.04117.84
5.6.170.0190.03317.72
5.6.160.0080.04017.84
5.6.150.0050.04417.84
5.6.140.0120.03517.85
5.6.130.0080.04117.79
5.6.120.0020.02718.02
5.6.110.0090.04217.89
5.6.100.0040.05017.79
5.6.90.0030.05217.82
5.6.80.0090.04017.59
5.6.70.0080.04017.45
5.6.60.0110.03917.68
5.6.50.0050.02617.65
5.6.40.0080.02517.63
5.6.30.0070.04017.42
5.6.20.0050.02617.55
5.6.10.0040.04717.54
5.6.00.0050.03917.59
5.5.380.0130.03817.70
5.5.370.0050.03817.47
5.5.360.0030.02917.54
5.5.350.0070.04317.45
5.5.340.0050.04917.84
5.5.330.0050.04817.77
5.5.320.0000.03117.87
5.5.310.0080.04017.80
5.5.300.0080.03017.70
5.5.290.0090.03317.60
5.5.280.0030.03317.82
5.5.270.0080.04517.77
5.5.260.0040.04617.90
5.5.250.0070.03017.67
5.5.240.0030.02417.52
5.5.230.0090.04617.42
5.5.220.0150.03217.39
5.5.210.0100.03517.29
5.5.200.0060.04017.40
5.5.190.0030.02517.44
5.5.180.0100.02217.30
5.5.170.0040.01114.51
5.5.160.0030.03717.51
5.5.150.0050.04217.30
5.5.140.0050.03717.39
5.5.130.0050.02617.29
5.5.120.0050.02017.31
5.5.110.0030.04417.28
5.5.100.0020.03317.43
5.5.90.0070.02017.37
5.5.80.0080.02117.39
5.5.70.0090.04017.40
5.5.60.0120.03017.52
5.5.50.0030.04117.30
5.5.40.0070.03017.34
5.5.30.0080.03817.23
5.5.20.0100.03217.42
5.5.10.0030.04217.36
5.5.00.0050.04517.17
5.4.450.0050.02915.43
5.4.440.0070.03915.49
5.4.430.0070.02715.41
5.4.420.0080.02015.44
5.4.410.0000.04715.40
5.4.400.0020.04415.13
5.4.390.0070.02615.08
5.4.380.0100.02215.23
5.4.370.0060.04115.20
5.4.360.0080.02115.22
5.4.350.0020.04415.29
5.4.340.0020.04215.19
5.4.330.0030.00311.35
5.4.320.0020.03015.28
5.4.310.0080.03915.04
5.4.300.0030.02215.13
5.4.290.0130.01615.29
5.4.280.0070.03615.26
5.4.270.0020.02215.31
5.4.260.0020.04015.24
5.4.250.0060.02015.23
5.4.240.0100.01715.21
5.4.230.0060.02015.20
5.4.220.0080.03715.23
5.4.210.0050.03215.16
5.4.200.0020.02315.01
5.4.190.0050.02015.08
5.4.180.0040.02215.21
5.4.170.0100.03014.95
5.4.160.0030.02215.08
5.4.150.0090.02315.30
5.4.140.0080.03813.75
5.4.130.0050.03513.87
5.4.120.0030.01813.90
5.4.110.0100.03713.95
5.4.100.0000.04213.95
5.4.90.0090.02413.88
5.4.80.0030.03913.94
5.4.70.0030.02114.02
5.4.60.0050.03513.78
5.4.50.0080.03613.79
5.4.40.0070.02013.92
5.4.30.0050.03413.80
5.4.20.0050.02513.91
5.4.10.0050.03913.86
5.4.00.0000.02813.64
5.3.290.0000.02912.93
5.3.280.0050.03912.89
5.3.270.0120.03512.81
5.3.260.0070.03312.88
5.3.250.0070.03712.85
5.3.240.0080.03812.92
5.3.230.0040.03812.90
5.3.220.0000.04012.86
5.3.210.0050.03912.86
5.3.200.0050.04012.82
5.3.190.0030.02212.89
5.3.180.0100.03512.84
5.3.170.0050.04112.79
5.3.160.0050.01912.79
5.3.150.0030.03912.84
5.3.140.0080.02312.87
5.3.130.0100.02212.78
5.3.120.0070.02412.81
5.3.110.0050.02612.88
5.3.100.0030.02012.62
5.3.90.0080.03712.58
5.3.80.0080.02912.59
5.3.70.0080.04012.60
5.3.60.0000.02112.58
5.3.50.0070.03912.59
5.3.40.0020.04312.55
5.3.30.0070.02012.57
5.3.20.0080.02912.38
5.3.10.0100.02512.41
5.3.00.0040.02712.36

preferences:
50.43 ms | 401 KiB | 5 Q