3v4l.org

run code in 300+ PHP versions simultaneously
<?php function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true) { if($suffix) $suffixStr = "…"; else $suffixStr = ""; if(function_exists("mb_substr")) return mb_substr($str, $start, $length, $charset).$suffixStr; elseif(function_exists('iconv_substr')) { return iconv_substr($str,$start,$length,$charset).$suffixStr; } $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; preg_match_all($re[$charset], $str, $match); $slice = join("",array_slice($match[0], $start, $length)); return $slice.$suffixStr; } function u8_title_substr($str, $width = 0, $end = '...', $x3 = 0) { global $CFG; // 全局变量保存 x3 的值 if ($width <= 0 || $width >= strlen($str)) { return $str; } $arr = str_split($str); $len = count($arr); $w = 0; $width *= 10; // 不同字节编码字符宽度系数 $x1 = 11; // ASCII $x2 = 16; $x3 = $x3===0 ? ( $CFG['cf3'] > 0 ? $CFG['cf3']*10 : $x3 = 21 ) : $x3*10; $x4 = $x3; // http://zh.wikipedia.org/zh-cn/UTF8 for ($i = 0; $i < $len; $i++) { if ($w >= $width) { $e = $end; break; } $c = ord($arr[$i]); if ($c <= 127) { $w += $x1; } elseif ($c >= 192 && $c <= 223) { // 2字节头 $w += $x2; $i += 1; } elseif ($c >= 224 && $c <= 239) { // 3字节头 $w += $x3; $i += 2; } elseif ($c >= 240 && $c <= 247) { // 4字节头 $w += $x4; $i += 3; } } return implode('', array_slice($arr, 0, $i) ). $e; } $a = '测试这是一个测试'; //$a = 'xxxxbbbbbnnn'; $b = u8_title_substr($a,0,5,15); var_dump($b); ?>

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.0090.00616.75
8.3.50.0080.01021.94
8.3.40.0140.00718.68
8.3.30.0030.01019.09
8.3.20.0050.00320.35
8.3.10.0070.00023.71
8.3.00.0030.00519.13
8.2.180.0060.00918.29
8.2.170.0140.00022.96
8.2.160.0040.01120.52
8.2.150.0040.00424.18
8.2.140.0030.00624.66
8.2.130.0090.00926.16
8.2.120.0000.00722.08
8.2.110.0060.00320.99
8.2.100.0060.00617.91
8.2.90.0030.00619.22
8.2.80.0000.00817.97
8.2.70.0000.00817.63
8.2.60.0090.00017.80
8.2.50.0000.00818.10
8.2.40.0040.00420.58
8.2.30.0000.00717.93
8.2.20.0000.00917.58
8.2.10.0030.00518.06
8.2.00.0040.00417.82
8.1.280.0090.00525.92
8.1.270.0000.00922.14
8.1.260.0060.00326.35
8.1.250.0070.00028.09
8.1.240.0000.01222.02
8.1.230.0110.00022.63
8.1.220.0000.00917.78
8.1.210.0030.00618.77
8.1.200.0060.00317.35
8.1.190.0000.00817.23
8.1.180.0040.00418.10
8.1.170.0040.00418.65
8.1.160.0040.00419.02
8.1.150.0040.00418.66
8.1.140.0000.00717.53
8.1.130.0030.00317.89
8.1.120.0040.00417.38
8.1.110.0000.00717.44
8.1.100.0030.00417.46
8.1.90.0030.00517.53
8.1.80.0030.00617.43
8.1.70.0000.00717.43
8.1.60.0000.00917.62
8.1.50.0060.00317.43
8.1.40.0040.00417.52
8.1.30.0090.00017.65
8.1.20.0040.00417.73
8.1.10.0050.00317.46
8.1.00.0040.00417.29
8.0.300.0030.00618.77
8.0.290.0000.00716.88
8.0.280.0040.00418.43
8.0.270.0070.00017.32
8.0.260.0000.00816.92
8.0.250.0070.00017.05
8.0.240.0040.00417.04
8.0.230.0030.00316.95
8.0.220.0000.00816.96
8.0.210.0050.00216.85
8.0.200.0050.00317.05
8.0.190.0030.00717.04
8.0.180.0080.00016.98
8.0.170.0000.00917.02
8.0.160.0030.00317.04
8.0.150.0000.00716.84
8.0.140.0040.00416.94
8.0.130.0050.00013.46
8.0.120.0000.00716.90
8.0.110.0000.00716.95
8.0.100.0070.00017.03
8.0.90.0030.00616.96
8.0.80.0000.01517.00
8.0.70.0030.00516.91
8.0.60.0040.00416.83
8.0.50.0040.00416.82
8.0.30.0070.01217.03
8.0.20.0080.01117.40
8.0.10.0000.00717.05
8.0.00.0130.00916.71
7.4.330.0000.00515.21
7.4.320.0000.00716.43
7.4.300.0030.00516.64
7.4.290.0030.00616.45
7.4.280.0000.00716.52
7.4.270.0070.00016.59
7.4.260.0100.00016.55
7.4.250.0050.00316.55
7.4.240.0020.00516.60
7.4.230.0000.00816.63
7.4.220.0060.01016.48
7.4.210.0110.00916.64
7.4.200.0000.00716.57
7.4.190.0000.00716.39
7.4.160.0120.00616.49
7.4.150.0140.00317.40
7.4.140.0150.00717.86
7.4.130.0140.00616.45
7.4.120.0060.01116.51
7.4.110.0100.00716.57
7.4.100.0080.00816.61
7.4.90.0100.00716.57
7.4.80.0040.02019.39
7.4.70.0120.00616.57
7.4.60.0040.01316.55
7.4.50.0000.00616.26
7.4.40.0100.00722.77
7.4.30.0140.00316.47
7.4.10.0000.01616.32
7.4.00.0020.01515.85
7.3.330.0030.00313.19
7.3.320.0050.00013.14
7.3.310.0070.00016.37
7.3.300.0000.00716.19
7.3.290.0100.00916.29
7.3.280.0050.01016.32
7.3.270.0100.00717.40
7.3.260.0090.00916.55
7.3.250.0150.00516.55
7.3.240.0150.00916.69
7.3.230.0110.01116.55
7.3.210.0090.00916.69
7.3.200.0110.00719.39
7.3.190.0100.00716.30
7.3.180.0100.00716.54
7.3.170.0190.00316.27
7.3.160.0040.01116.35
7.3.130.0130.00616.26
7.3.120.0070.00915.61
7.3.110.0030.01016.30
7.3.100.0070.01016.34
7.3.90.0000.01416.57
7.3.80.0140.00316.22
7.3.70.0060.00616.43
7.3.60.0070.01016.28
7.3.50.0000.01416.38
7.3.40.0080.01216.32
7.3.30.0050.01116.46
7.3.20.0160.00618.22
7.3.10.0070.01017.33
7.3.00.0070.00817.16
7.2.330.0150.00316.61
7.2.320.0000.01616.57
7.2.310.0070.01016.75
7.2.300.0070.01816.73
7.2.290.0090.00916.53
7.2.260.0100.01016.46
7.2.250.0030.01916.38
7.2.240.0060.00916.34
7.2.230.0160.00316.62
7.2.220.0030.00716.71
7.2.210.0030.00616.70
7.2.200.0110.00716.63
7.2.190.0040.01716.54
7.2.180.0030.01616.26
7.2.170.0080.00816.36
7.2.160.0060.01316.61
7.2.150.0150.00818.35
7.2.140.0080.01518.27
7.2.130.0050.01217.16
7.2.120.0120.00517.19
7.2.110.0080.00917.21
7.2.100.0070.00817.39
7.2.90.0080.01017.20
7.2.80.0080.01017.30
7.2.70.0090.01017.27
7.2.60.0080.00617.04
7.2.50.0070.00817.27
7.2.40.0060.01017.38
7.2.30.0050.00917.42
7.2.20.0060.00817.34
7.2.10.0070.00717.22
7.2.00.0090.00717.44
7.1.330.0000.01917.36
7.1.320.0100.00717.38
7.1.310.0130.00317.25
7.1.300.0100.00617.36
7.1.290.0090.00317.32
7.1.280.0080.01017.16
7.1.270.0110.01117.33
7.1.260.0140.01017.37
7.1.250.0030.01316.43
7.1.240.0080.00616.59
7.1.230.0080.00816.62
7.1.220.0050.01016.51
7.1.210.0080.00816.59
7.1.200.0100.00616.24
7.1.190.0100.00516.37
7.1.180.0110.00316.49
7.1.170.0100.00316.34
7.1.160.0040.00716.67
7.1.150.0030.00816.55
7.1.140.0040.00916.38
7.1.130.0070.00716.57
7.1.120.0070.00716.59
7.1.110.0060.00716.58
7.1.100.0080.00516.60
7.1.90.0080.00816.40
7.1.80.0030.01116.33
7.1.70.0060.00816.86
7.1.60.0090.00917.49
7.1.50.0040.00716.67
7.1.40.0060.00716.66
7.1.30.0080.00816.49
7.1.20.0030.01216.60
7.1.10.0100.00616.33
7.1.00.0040.03118.44
7.0.330.0050.00916.26
7.0.320.0080.00816.16
7.0.310.0060.00816.19
7.0.300.0150.00115.88
7.0.290.0050.00915.95
7.0.280.0100.00515.98
7.0.270.0060.00816.02
7.0.260.0040.00816.32
7.0.250.0040.00916.26
7.0.240.0050.00916.20
7.0.230.0070.00716.08
7.0.220.0030.00716.19
7.0.210.0050.00916.13
7.0.200.0050.00816.43
7.0.190.0060.00616.27
7.0.180.0060.00616.12
7.0.170.0030.01216.25
7.0.160.0050.00916.07
7.0.150.0060.00816.10
7.0.140.0060.02818.09
7.0.130.0050.00816.18
7.0.120.0060.00916.32
7.0.110.0080.00616.15
7.0.100.0110.02917.44
7.0.90.0070.03317.45
7.0.80.0050.03217.43
7.0.70.0170.03217.48
7.0.60.0160.03017.46
7.0.50.0110.02217.56
7.0.40.0050.02016.22
7.0.30.0050.03116.15
7.0.20.0040.03716.18
7.0.10.0070.02716.20
7.0.00.0060.03516.15
5.6.400.0040.01716.16
5.6.390.0100.00715.69
5.6.380.0060.00715.15
5.6.370.0030.01015.06
5.6.360.0070.00415.15
5.6.350.0030.01015.10
5.6.340.0010.01115.16
5.6.330.0050.00914.72
5.6.320.0020.01015.04
5.6.310.0040.00814.94
5.6.300.0070.00714.82
5.6.290.0060.00514.98
5.6.280.0060.02817.20
5.6.270.0050.01015.25
5.6.260.0090.00614.98
5.6.250.0070.02616.86
5.6.240.0070.03316.91
5.6.230.0070.03516.88
5.6.220.0090.02716.96
5.6.210.0090.02716.80
5.6.200.0080.03516.96
5.6.190.0070.03416.99
5.6.180.0070.03216.98
5.6.170.0050.02717.08
5.6.160.0040.03116.93
5.6.150.0070.02816.96
5.6.140.0060.03316.94
5.6.130.0080.01717.11
5.6.120.0040.03517.19
5.6.110.0050.03216.96
5.6.100.0050.01916.95
5.6.90.0040.02217.06
5.6.80.0020.01916.78
5.6.70.0030.02216.75
5.6.60.0080.01616.78
5.6.50.0080.01516.86
5.6.40.0080.01516.64
5.6.30.0070.01716.74
5.6.20.0020.02116.67
5.6.10.0080.01416.67
5.6.00.0060.01616.70
5.5.380.0040.03415.71
5.5.370.0040.03215.68
5.5.360.0060.03315.71
5.5.350.0090.02315.67
5.5.340.0100.01315.81
5.5.330.0020.03315.80
5.5.320.0050.03215.82
5.5.310.0070.03115.80
5.5.300.0050.03315.92
5.5.290.0090.02915.84
5.5.280.0050.02415.85
5.5.270.0060.03015.74
5.5.260.0090.02715.81
5.5.250.0040.01915.67
5.5.240.0010.01915.61
5.5.230.0060.01515.72
5.5.220.0070.01815.66
5.5.210.0020.01715.63
5.5.200.0070.01515.54
5.5.190.0010.02015.57
5.5.180.0010.02115.56
5.5.170.0080.00513.25
5.5.160.0060.01515.62
5.5.150.0070.01515.51
5.5.140.0060.01815.77
5.5.130.0060.01615.61
5.5.120.0050.01515.51
5.5.110.0030.02115.63
5.5.100.0100.01315.35
5.5.90.0020.01615.68
5.5.80.0040.01715.68
5.5.70.0020.03215.57
5.5.60.0030.02315.53
5.5.50.0030.01615.55
5.5.40.0030.02015.52
5.5.30.0090.01415.55
5.5.20.0030.01815.58
5.5.10.0040.02015.37
5.5.00.0060.01615.58
5.4.450.0060.02914.41
5.4.440.0040.03114.31
5.4.430.0080.02714.37
5.4.420.0030.01814.29
5.4.410.0070.01414.25
5.4.400.0040.01614.28
5.4.390.0020.01714.22
5.4.380.0030.01514.03
5.4.370.0010.01914.29
5.4.360.0030.01914.25
5.4.350.0030.01814.23
5.4.340.0030.01714.19
5.4.330.0060.00611.82
5.4.320.0040.01714.35
5.4.310.0060.01314.23
5.4.300.0030.01614.18
5.4.290.0070.01414.27
5.4.280.0010.01814.25
5.4.270.0040.01714.25
5.4.260.0060.01414.26
5.4.250.0040.01614.28
5.4.240.0020.01914.26
5.4.230.0030.01614.23
5.4.220.0050.01714.28
5.4.210.0040.01614.28
5.4.200.0070.01414.09
5.4.190.0050.01214.16
5.4.180.0040.01614.25
5.4.170.0050.01414.26
5.4.160.0070.01314.09
5.4.150.0060.01614.18
5.4.140.0050.01913.34
5.4.130.0020.01913.30
5.4.120.0020.01613.34
5.4.110.0060.01713.30
5.4.100.0030.02013.28
5.4.90.0060.01713.36
5.4.80.0020.01913.45
5.4.70.0050.02713.39
5.4.60.0070.02613.28
5.4.50.0070.02613.33
5.4.40.0050.02513.40
5.4.30.0060.02613.27
5.4.20.0080.02213.28
5.4.10.0040.02213.39
5.4.00.0070.02613.11
5.3.290.0060.02312.80
5.3.280.0020.01712.57
5.3.270.0020.01812.68
5.3.260.0050.01512.74
5.3.250.0080.01312.75
5.3.240.0070.01212.76
5.3.230.0030.01712.68
5.3.220.0060.01512.59
5.3.210.0030.01612.58
5.3.200.0040.01412.63
5.3.190.0030.02512.58
5.3.180.0010.02012.77
5.3.170.0040.02812.71
5.3.160.0070.02512.72
5.3.150.0050.02112.69
5.3.140.0060.02812.60
5.3.130.0080.01712.66
5.3.120.0010.03312.66
5.3.110.0040.02412.67
5.3.100.0020.01812.48
5.3.90.0030.03112.50
5.3.80.0040.02912.42
5.3.70.0060.03112.46
5.3.60.0050.02512.54
5.3.50.0070.03012.45
5.3.40.0040.03012.45
5.3.30.0070.02512.42
5.3.20.0050.01812.44
5.3.10.0060.02412.26
5.3.00.0050.02712.26
5.2.170.0050.02810.44
5.2.160.0050.03210.49
5.2.150.0060.03510.41
5.2.140.0040.01810.41
5.2.130.0030.03610.40
5.2.120.0030.03210.43
5.2.110.0060.03310.40
5.2.100.0000.02910.39
5.2.90.0030.03110.16
5.2.80.0050.02510.28
5.2.70.0020.03410.18
5.2.60.0000.03810.17
5.2.50.0090.03010.14
5.2.40.0030.03410.31
5.2.30.0030.03510.24
5.2.20.0060.02110.22
5.2.10.0070.02910.10
5.2.00.0030.03410.00
5.1.60.0040.0309.31
5.1.50.0030.0219.29
5.1.40.0020.0319.28
5.1.30.0020.0339.59
5.1.20.0050.0159.58
5.1.10.0060.0279.41
5.1.00.0060.0279.16
5.0.50.0000.0198.46
5.0.40.0050.0218.46
5.0.30.0060.0338.46
5.0.20.0030.0188.46
5.0.10.0020.0228.46
5.0.00.0030.0318.46
4.4.90.0030.0108.46
4.4.80.0010.0218.46
4.4.70.0050.0188.46
4.4.60.0050.0168.46
4.4.50.0020.0198.46
4.4.40.0000.0188.46
4.4.30.0040.0168.46
4.4.20.0030.0188.46
4.4.10.0030.0168.46
4.4.00.0020.0308.46
4.3.110.0020.0208.46
4.3.100.0030.0188.46
4.3.90.0050.0158.46
4.3.80.0040.0208.46
4.3.70.0000.0138.46
4.3.60.0020.0178.46
4.3.50.0030.0108.46
4.3.40.0030.0268.46
4.3.30.0000.0218.46
4.3.20.0020.0178.46
4.3.10.0020.0178.46
4.3.00.0000.0188.46

preferences:
36.65 ms | 401 KiB | 5 Q