3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * check matching of braces * * @param string $src target string to check * @return bool */ function brace_check($src) { $open_braces = str_split("({["); $close_braces = str_split(")}]"); $braces = array_merge($open_braces, $close_braces); $tokens = token_get_all($src); // bracesを含むであろう文字列トークン以外は捨てる $tokens = array_filter($tokens,function($item){ return is_string($item); }); $open_brace_stack = array(); foreach($tokens as $key => $t){ if (in_array($t,$open_braces)){ // 開括弧なら開括弧スタックに乗せる array_push( $open_brace_stack, $t); } elseif (in_array($t,$close_braces)){ if ( empty($open_brace_stack) ){ // 開括弧スタックが空ならエラー return false; } // 括弧の対応を確認(開括弧スタックのトップと現在の文字) $open_top = array_pop($open_brace_stack); $idx_open = array_search($open_top, $open_braces); $idx_close = array_search($t, $close_braces); if ( $idx_open !== $idx_close ){ return false; } } } return true; } //========================= // test code $html_case = <<<HTML <?php ?> <html> ... <ul> <li>1)...</li> <li>2)...</li> </ul> ... <?php ?> ... </html> HTML; $expressions = array(")(){}","[]({})","([])","{()[]}","([)]",$html_case,'This is ${great}'); var_dump(array_map('brace_check', $expressions));

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.01416.50
8.3.50.0090.01121.28
8.3.40.0110.00418.79
8.3.30.0100.00318.95
8.3.20.0070.00020.29
8.3.10.0050.00323.48
8.3.00.0050.00317.50
8.2.180.0090.01216.88
8.2.170.0000.01422.96
8.2.160.0100.00320.35
8.2.150.0060.00324.18
8.2.140.0080.00024.66
8.2.130.0060.00326.16
8.2.120.0000.00721.01
8.2.110.0030.00721.05
8.2.100.0040.00817.84
8.2.90.0040.00418.34
8.2.80.0000.00818.07
8.2.70.0030.00517.91
8.2.60.0080.00017.89
8.2.50.0030.00518.07
8.2.40.0080.00019.88
8.2.30.0050.00318.09
8.2.20.0000.00817.64
8.2.10.0040.00418.09
8.2.00.0040.00418.09
8.1.280.0110.00725.92
8.1.270.0000.00720.20
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00322.46
8.1.230.0070.00422.65
8.1.220.0040.00417.74
8.1.210.0040.00418.79
8.1.200.0040.00417.35
8.1.190.0080.00017.10
8.1.180.0050.00318.10
8.1.170.0050.00520.36
8.1.160.0040.00422.01
8.1.150.0070.00018.94
8.1.140.0060.00317.54
8.1.130.0030.00517.86
8.1.120.0000.00717.56
8.1.110.0040.00417.51
8.1.100.0040.00417.52
8.1.90.0080.00017.55
8.1.80.0000.00817.41
8.1.70.0030.00317.36
8.1.60.0080.00017.62
8.1.50.0080.00017.52
8.1.40.0040.00417.57
8.1.30.0030.00617.56
8.1.20.0080.00017.58
8.1.10.0030.00617.42
8.1.00.0000.00817.34
8.0.300.0060.00320.17
8.0.290.0030.00617.00
8.0.280.0000.00718.54
8.0.270.0030.00317.40
8.0.260.0000.00717.31
8.0.250.0000.00717.00
8.0.240.0060.00017.05
8.0.230.0000.00717.06
8.0.220.0030.00316.89
8.0.210.0040.00416.99
8.0.200.0070.00017.01
8.0.190.0040.00417.08
8.0.180.0030.00516.99
8.0.170.0040.00416.92
8.0.160.0030.00317.02
8.0.150.0050.00316.85
8.0.140.0060.00317.04
8.0.130.0030.00313.41
8.0.120.0050.00316.95
8.0.110.0000.00817.06
8.0.100.0050.00216.95
8.0.90.0000.00716.93
8.0.80.0110.01117.04
8.0.70.0000.00816.96
8.0.60.0040.00416.93
8.0.50.0070.00016.93
8.0.30.0090.01317.24
8.0.20.0110.00817.43
8.0.10.0090.00016.99
8.0.00.0120.00617.03
7.4.330.0020.00215.03
7.4.320.0000.00616.41
7.4.300.0060.00016.66
7.4.290.0030.00316.59
7.4.280.0030.00516.53
7.4.270.0030.00516.61
7.4.260.0030.00516.50
7.4.250.0080.00016.55
7.4.240.0030.00616.49
7.4.230.0030.00316.65
7.4.220.0170.00316.50
7.4.210.0090.00616.65
7.4.200.0080.00016.35
7.4.160.0100.01016.58
7.4.150.0160.00317.40
7.4.140.0180.00517.86
7.4.130.0120.00816.61
7.4.120.0100.00916.47
7.4.110.0070.01016.64
7.4.100.0220.00016.60
7.4.90.0100.01016.64
7.4.80.0070.01619.39
7.4.70.0120.00916.70
7.4.60.0140.00316.63
7.4.50.0040.00416.76
7.4.40.0160.00016.62
7.4.30.0080.00916.48
7.4.10.0050.01414.96
7.4.00.0060.01014.98
7.3.330.0050.00013.39
7.3.320.0060.00613.45
7.3.310.0080.00016.41
7.3.300.0000.00616.30
7.3.290.0060.00016.38
7.3.280.0060.01016.35
7.3.270.0090.00917.40
7.3.260.0140.00316.56
7.3.250.0120.00516.47
7.3.240.0070.01116.33
7.3.230.0100.00716.63
7.3.210.0140.00416.48
7.3.200.0040.01319.39
7.3.190.0060.01516.76
7.3.180.0060.00916.55
7.3.170.0100.00716.50
7.3.160.0100.00616.47
7.3.130.0080.00715.03
7.3.120.0070.01115.07
7.3.110.0060.01114.86
7.3.100.0060.00614.95
7.3.90.0040.00814.72
7.3.80.0040.00914.80
7.3.70.0060.00814.88
7.3.60.0030.00814.97
7.3.50.0040.00914.82
7.3.40.0030.01114.79
7.3.30.0070.00514.82
7.3.20.0060.00716.67
7.3.10.0050.00716.74
7.3.00.0100.00416.75
7.2.330.0030.01516.69
7.2.320.0070.01016.57
7.2.310.0060.01216.83
7.2.300.0030.01416.68
7.2.290.0110.00816.59
7.2.260.0050.01315.06
7.2.250.0060.01314.97
7.2.240.0040.00915.18
7.2.230.0030.01215.12
7.2.220.0060.00615.17
7.2.210.0040.00815.09
7.2.200.0080.00514.94
7.2.190.0050.00814.98
7.2.180.0040.00914.92
7.2.170.0010.01315.03
7.2.160.0060.00614.92
7.2.150.0070.00316.93
7.2.140.0010.01116.89
7.2.130.0030.01016.91
7.2.120.0070.00616.80
7.2.110.0030.00916.92
7.2.100.0080.00717.01
7.2.90.0050.00716.80
7.2.80.0070.00816.79
7.2.70.0070.00517.00
7.2.60.0060.00816.99
7.2.50.0080.00516.79
7.2.40.0030.00816.99
7.2.30.0090.00316.82
7.2.20.0040.00716.96
7.2.10.0080.00816.93
7.2.00.0060.01016.84
7.1.330.0030.00715.73
7.1.320.0020.01215.66
7.1.310.0100.00415.79
7.1.300.0010.01015.76
7.1.290.0060.00815.83
7.1.280.0070.00415.57
7.1.270.0070.00515.70
7.1.260.0050.00515.58
7.1.250.0030.01015.63
7.1.240.0030.00915.60
7.1.230.0070.00715.62
7.1.220.0020.01015.69
7.1.210.0060.00615.67
7.1.200.0070.00415.83
7.1.190.0050.01015.79
7.1.180.0050.00815.71
7.1.170.0030.01015.68
7.1.160.0020.00915.64
7.1.150.0060.00715.74
7.1.140.0030.01215.57
7.1.130.0080.00615.46
7.1.120.0060.00415.59
7.1.110.0080.00315.84
7.1.100.0070.00516.54
7.1.90.0060.00715.90
7.1.80.0050.00815.79
7.1.70.0040.00616.27
7.1.60.0090.00917.05
7.1.50.0040.01216.14
7.1.40.0070.00715.91
7.1.30.0040.01015.75
7.1.20.0030.01215.79
7.1.10.0060.00815.66
7.1.00.0060.02818.01
7.0.330.0050.00515.43
7.0.320.0020.00714.96
7.0.310.0090.00515.02
7.0.300.0090.00315.19
7.0.290.0050.00715.32
7.0.280.0040.00715.35
7.0.270.0050.00615.32
7.0.260.0050.00715.23
7.0.250.0040.00915.37
7.0.240.0090.00315.45
7.0.230.0050.00915.38
7.0.220.0070.00615.42
7.0.210.0110.00315.37
7.0.200.0060.00515.94
7.0.190.0070.00615.41
7.0.180.0080.00415.39
7.0.170.0030.00715.50
7.0.160.0050.01115.45
7.0.150.0020.01015.45
7.0.140.0080.00715.20
7.0.130.0030.00915.54
7.0.120.0030.00515.56
7.0.110.0070.01817.03
7.0.100.0080.01716.88
7.0.90.0090.01916.83
7.0.80.0060.02817.00
7.0.70.0040.02016.93
7.0.60.0070.01816.90
7.0.50.0010.02217.02
7.0.40.0080.01615.60
7.0.30.0050.02015.52
7.0.20.0020.02015.59
7.0.10.0030.01815.55
7.0.00.0070.02015.59
5.6.400.0060.00614.04
5.6.390.0040.00714.36
5.6.380.0050.01114.27
5.6.370.0090.00514.30
5.6.360.0030.01014.25
5.6.350.0040.00713.99
5.6.340.0020.00914.37
5.6.330.0040.00814.14
5.6.320.0110.00214.38
5.6.310.0040.01314.40
5.6.300.0010.00814.18
5.6.290.0080.00914.30
5.6.280.0060.03016.52
5.6.270.0070.00514.31
5.6.260.0070.01716.39
5.6.250.0080.01516.35
5.6.240.0080.02516.46
5.6.230.0090.02316.49
5.6.220.0070.01816.40
5.6.210.0070.01516.45
5.6.200.0040.02216.45
5.6.190.0080.01516.45
5.6.180.0060.01616.32
5.6.170.0020.02216.38
5.6.160.0050.02016.54
5.6.150.0020.02216.33
5.6.140.0010.02016.41
5.6.130.0060.01216.31
5.6.120.0030.02216.49
5.6.110.0060.02216.42
5.6.100.0040.02116.23
5.6.90.0080.01216.32
5.6.80.0040.01816.12
5.6.70.0010.03216.30
5.6.60.0060.02616.10
5.6.50.0050.03416.11
5.6.40.0060.03116.21
5.6.30.0100.03016.21
5.6.20.0060.03216.12
5.6.10.0060.02916.15
5.6.00.0030.03616.28
5.5.380.0050.01415.40
5.5.370.0040.01715.34
5.5.360.0050.01815.35
5.5.350.0110.01315.32
5.5.340.0090.01615.55
5.5.330.0100.01315.30
5.5.320.0070.02515.54
5.5.310.0040.01815.52
5.5.300.0040.01615.61
5.5.290.0050.01815.49
5.5.280.0060.01715.57
5.5.270.0040.01915.45
5.5.260.0060.02815.55
5.5.250.0050.02215.38
5.5.240.0070.02715.34
5.5.230.0100.02815.31
5.5.220.0040.03015.33
5.5.210.0030.03415.32
5.5.200.0050.03015.36
5.5.190.0030.03215.18
5.5.180.0120.02615.31
5.5.170.0050.00914.08
5.5.160.0070.03115.32
5.5.150.0060.01915.26
5.5.140.0030.03715.41
5.5.130.0080.03215.25
5.5.120.0040.02215.13
5.5.110.0040.03015.38
5.5.100.0080.02815.21
5.5.90.0080.02815.10
5.5.80.0060.02915.03
5.5.70.0020.03315.07
5.5.60.0040.02115.39
5.5.50.0060.02015.19
5.5.40.0050.02615.09
5.5.30.0060.01915.39
5.5.20.0040.02415.21
5.5.10.0060.03115.21
5.5.00.0010.03615.25
5.4.450.0050.01914.00
5.4.440.0080.01014.04
5.4.430.0040.01813.80
5.4.420.0020.01813.64
5.4.410.0030.02613.76
5.4.400.0020.01513.60
5.4.390.0020.02513.61
5.4.380.0040.01613.65
5.4.370.0050.02813.68
5.4.360.0030.02913.78
5.4.350.0060.01413.70
5.4.340.0030.03213.73
5.4.330.0050.00311.12
5.4.320.0040.02913.65
5.4.310.0040.02013.54
5.4.300.0050.02713.72
5.4.290.0060.02913.71
5.4.280.0060.02113.77
5.4.270.0040.01913.77
5.4.260.0050.02913.61
5.4.250.0060.02813.64
5.4.240.0080.03113.77
5.4.230.0080.02913.64
5.4.220.0050.02813.67
5.4.210.0050.03013.52
5.4.200.0040.02813.61
5.4.190.0040.03313.73
5.4.180.0020.03113.71
5.4.170.0070.02413.59
5.4.160.0080.02413.66
5.4.150.0080.02513.52
5.4.140.0080.02712.95
5.4.130.0080.02612.81
5.4.120.0070.02512.75
5.4.110.0030.02012.90
5.4.100.0020.02112.74
5.4.90.0090.02612.96
5.4.80.0060.02612.79
5.4.70.0050.01812.75
5.4.60.0070.01512.64
5.4.50.0100.01612.92
5.4.40.0010.02812.72
5.4.30.0070.02512.76
5.4.20.0030.02712.85
5.4.10.0030.03012.81
5.4.00.0040.02712.66
5.3.290.0170.06714.70
5.3.280.0070.04314.75
5.3.270.0030.04714.64
5.3.260.0100.07014.61
5.3.250.0100.05714.61
5.3.240.0070.08014.63
5.3.230.0100.07714.69
5.3.220.0100.07014.65
5.3.210.0030.07714.70
5.3.200.0070.07314.43
5.3.190.0070.04314.52
5.3.180.0030.07714.58
5.3.170.0030.08314.70
5.3.160.0070.04014.71
5.3.150.0070.07014.62
5.3.140.0100.06314.65
5.3.130.0070.07714.56
5.3.120.0100.07314.56
5.3.110.0000.04014.51
5.3.100.0000.04714.19
5.3.90.0000.04014.17
5.3.80.0100.07014.12
5.3.70.0130.06314.11
5.3.60.0100.07714.24
5.3.50.0000.07713.83
5.3.40.0100.07013.97
5.3.30.0100.07013.88
5.3.20.0070.07313.55
5.3.10.0100.03713.62
5.3.00.0100.06713.64
5.2.170.0030.03711.93
5.2.160.0030.03711.93
5.2.150.0100.06311.93
5.2.140.0130.05711.93
5.2.130.0130.05311.93
5.2.120.0070.03711.93
5.2.110.0070.03011.93
5.2.100.0000.06311.93
5.2.90.0030.06311.93
5.2.80.0070.05311.93
5.2.70.0100.05711.93
5.2.60.0070.05011.93
5.2.50.0100.05711.93
5.2.40.0070.06011.93
5.2.30.0100.06011.93
5.2.20.0030.05711.93
5.2.10.0000.03311.93
5.2.00.0000.06311.93
5.1.60.0030.03011.93
5.1.50.0030.05011.93
5.1.40.0000.03311.93
5.1.30.0070.05311.93
5.1.20.0000.03711.93
5.1.10.0030.05711.93
5.1.00.0030.05311.93
5.0.50.0070.04311.93
5.0.40.0100.04011.93
5.0.30.0030.06711.93
5.0.20.0000.04311.93
5.0.10.0030.03311.93
5.0.00.0030.05711.93
4.4.90.0000.03711.93
4.4.80.0030.03311.93
4.4.70.0100.02711.93
4.4.60.0030.03711.93
4.4.50.0000.03711.93
4.4.40.0000.05311.93
4.4.30.0000.03011.93
4.4.20.0030.03311.93
4.4.10.0070.03011.93
4.4.00.0030.05311.93
4.3.110.0030.03311.93
4.3.100.0030.02311.93
4.3.90.0030.02011.93
4.3.80.0030.05011.93
4.3.70.0030.03011.93
4.3.60.0000.03311.93
4.3.50.0000.01311.93
4.3.40.0000.04711.93
4.3.30.0000.03711.93
4.3.20.0100.02711.93
4.3.10.0000.03711.93
4.3.00.0000.03311.93

preferences:
59.92 ms | 401 KiB | 5 Q