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)
5.6.90.0100.08021.13
5.6.80.0030.04020.52
5.5.250.0170.06020.70
5.5.240.0030.03720.08
5.4.410.0300.05318.84
5.4.400.0170.06718.77
5.4.390.0170.04718.63
5.4.380.0200.06718.75
5.4.370.0200.04318.57
5.4.360.0030.05718.79
5.4.350.0070.06018.72
5.4.340.0130.04718.80
5.4.320.0170.05018.78
5.4.310.0100.06018.71
5.4.300.0200.04318.77
5.4.290.0070.06318.82
5.4.280.0130.05718.61
5.4.270.0030.05718.53
5.4.260.0100.05018.65
5.4.250.0000.06018.57
5.4.240.0130.05018.62
5.4.230.0100.05018.81
5.4.220.0130.05018.48
5.4.210.0070.06018.50
5.4.200.0130.04716.64
5.4.190.0170.05018.75
5.4.180.0170.05318.78
5.4.170.0070.06718.56
5.4.160.0130.05018.51
5.4.150.0100.05318.75
5.4.140.0030.05716.20
5.4.130.0130.04316.26
5.4.120.0100.04716.46
5.4.110.0070.05016.23
5.4.100.0070.05316.38
5.4.90.0130.04716.35
5.4.80.0130.04716.22
5.4.70.0170.04716.31
5.4.60.0100.05016.34
5.4.50.0130.04316.30
5.4.40.0030.05716.23
5.4.30.0230.03716.41
5.4.20.0130.05016.41
5.4.10.0100.05316.30
5.4.00.0030.06315.87
5.3.290.0070.05714.88
5.3.280.0130.06014.63
5.3.270.0200.05314.72
5.3.260.0230.04014.71
5.3.250.0170.04314.72
5.3.240.0070.05314.64
5.3.230.0070.05314.82
5.3.220.0070.05314.62
5.3.210.0130.06014.61
5.3.200.0100.05014.71
5.3.190.0170.04314.76
5.3.180.0100.07014.57
5.3.170.0130.06714.61
5.3.160.0200.06014.57
5.3.150.0100.05314.59
5.3.140.0100.05314.57
5.3.130.0070.05714.55
5.3.120.0030.05714.76
5.3.110.0130.05014.66
5.3.100.0000.06014.15
5.3.90.0070.05314.05
5.3.80.0100.05014.25
5.3.70.0200.04314.13
5.3.60.0170.04314.22
5.3.50.0070.05313.98
5.3.40.0130.04714.03
5.3.30.0070.05313.95
5.3.20.0000.07013.72
5.3.10.0100.04713.71
5.3.00.0130.04713.85
5.2.170.0070.04311.17
5.2.160.0100.04011.12
5.2.150.0200.03011.17
5.2.140.0070.04311.14
5.2.130.0030.04311.32
5.2.120.0100.04011.16
5.2.110.0070.04011.09
5.2.100.0170.03011.13
5.2.90.0030.04311.12
5.2.80.0000.07011.20
5.2.70.0100.03711.13
5.2.60.0030.04311.16
5.2.50.0070.06311.12
5.2.40.0070.04011.03
5.2.30.0070.04011.09
5.2.20.0070.04011.07
5.2.10.0000.04310.88
5.2.00.0000.04710.90
5.1.60.0170.03010.02
5.1.50.0070.03710.04
5.1.40.0030.03310.16
5.1.30.0030.03710.32
5.1.20.0000.04310.35
5.1.10.0030.03710.14
5.1.00.0100.03310.26
5.0.50.0030.0308.55
5.0.40.0030.0278.61
5.0.30.0030.0438.26
5.0.20.0000.0308.32
5.0.10.0070.0278.22
5.0.00.0030.0438.34
4.4.90.0030.0235.88
4.4.80.0030.0235.93
4.4.70.0030.0235.91
4.4.60.0070.0175.86
4.4.50.0070.0275.95
4.4.40.0070.0305.98
4.4.30.0000.0235.94
4.4.20.0070.0205.96
4.4.10.0100.0175.95
4.4.00.0070.0305.99
4.3.110.0000.0275.81
4.3.100.0070.0205.86
4.3.90.0030.0275.80
4.3.80.0030.0375.88
4.3.70.0000.0235.84
4.3.60.0000.0235.87
4.3.50.0030.0235.77
4.3.40.0030.0335.85
4.3.30.0000.0234.55
4.3.20.0030.0204.55
4.3.10.0000.0234.52
4.3.00.0000.01716.51

preferences:
146.46 ms | 939 KiB | 8 Q