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,10); 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.0140.00718.22
8.3.50.0200.01021.98
8.3.40.0120.00318.85
8.3.30.0140.00418.79
8.3.20.0070.00718.79
8.3.10.0040.00421.15
8.3.00.0050.00221.73
8.2.180.0150.00018.24
8.2.170.0040.01122.96
8.2.160.0100.00720.43
8.2.150.0100.00725.66
8.2.140.0030.00624.66
8.2.130.0040.00426.16
8.2.120.0080.00319.27
8.2.110.0000.01022.27
8.2.100.0080.00417.72
8.2.90.0060.00319.30
8.2.80.0040.00417.97
8.2.70.0040.00417.63
8.2.60.0080.00017.93
8.2.50.0090.00018.07
8.2.40.0050.00318.09
8.2.30.0040.00421.13
8.2.20.0040.00417.73
8.2.10.0080.00017.67
8.2.00.0040.00717.81
8.1.280.0100.00625.92
8.1.270.0040.00423.99
8.1.260.0030.00626.35
8.1.250.0040.00428.09
8.1.240.0070.00320.09
8.1.230.0040.00720.87
8.1.220.0040.00418.77
8.1.210.0000.00818.97
8.1.200.0030.00617.38
8.1.190.0000.00717.53
8.1.180.0060.00318.10
8.1.170.0040.00418.64
8.1.160.0000.00718.76
8.1.150.0040.00418.67
8.1.140.0040.00417.41
8.1.130.0040.00417.89
8.1.120.0060.00317.46
8.1.110.0040.00417.50
8.1.100.0040.00417.48
8.1.90.0030.00517.45
8.1.80.0000.00817.55
8.1.70.0000.00717.36
8.1.60.0040.00417.63
8.1.50.0000.00717.51
8.1.40.0000.00817.49
8.1.30.0000.00817.57
8.1.20.0080.00017.68
8.1.10.0000.00717.47
8.1.00.0040.00417.32
8.0.300.0040.00420.07
8.0.290.0000.00817.16
8.0.280.0040.00418.40
8.0.270.0020.00517.34
8.0.260.0030.00316.89
8.0.250.0070.00016.96
8.0.240.0000.00817.03
8.0.230.0000.00816.88
8.0.220.0030.00317.01
8.0.210.0080.00016.99
8.0.200.0030.00316.97
8.0.190.0000.00717.01
8.0.180.0050.00216.88
8.0.170.0080.00016.88
8.0.160.0000.00717.03
8.0.150.0070.00016.94
8.0.140.0060.00616.97
8.0.130.0000.00513.48
8.0.120.0040.00416.92
8.0.110.0040.00416.83
8.0.100.0080.00016.89
8.0.90.0050.00216.86
8.0.80.0070.01016.87
8.0.70.0000.00716.85
8.0.60.0050.00316.96
8.0.50.0040.00417.02
8.0.30.0050.01517.25
8.0.20.0120.00917.40
8.0.10.0060.00316.91
8.0.00.0100.01316.80
7.4.330.0000.00516.83
7.4.320.0030.00616.54
7.4.300.0040.00416.51
7.4.290.0050.00216.54
7.4.280.0030.00316.53
7.4.270.0000.00716.55
7.4.260.0000.00613.31
7.4.250.0000.00716.57
7.4.240.0080.00016.66
7.4.230.0030.00316.60
7.4.220.0110.00916.42
7.4.210.0080.00816.56
7.4.200.0030.00316.50
7.4.190.0000.00716.50
7.4.160.0090.01316.53
7.4.150.0130.00617.40
7.4.140.0120.00717.86
7.4.130.0140.00616.59
7.4.120.0080.01216.47
7.4.110.0060.01016.58
7.4.100.0110.00616.50
7.4.90.0060.01216.49
7.4.80.0130.01119.39
7.4.70.0060.01216.52
7.4.60.0030.01516.49
7.4.50.0000.00916.24
7.4.40.0040.01122.77
7.4.30.0090.00716.52
7.4.10.0070.00715.10
7.4.00.0100.00814.91
7.3.330.0000.00613.14
7.3.320.0040.00413.34
7.3.310.0000.00716.22
7.3.300.0070.00016.34
7.3.290.0070.00716.33
7.3.280.0070.01016.34
7.3.270.0110.00617.40
7.3.260.0100.01018.24
7.3.250.0090.00816.54
7.3.240.0110.00616.57
7.3.230.0090.01716.39
7.3.210.0150.00416.50
7.3.200.0070.01019.39
7.3.190.0080.01116.36
7.3.180.0080.00816.38
7.3.170.0100.00716.58
7.3.160.0140.00316.42
7.3.130.0110.01114.88
7.3.120.0070.01014.77
7.3.110.0100.01014.60
7.3.100.0060.01014.84
7.3.90.0060.01214.82
7.3.80.0100.00614.98
7.3.70.0080.00814.76
7.3.60.0060.00614.93
7.3.50.0040.01114.60
7.3.40.0060.00314.86
7.3.30.0030.01414.76
7.3.20.0130.00316.68
7.3.10.0000.00916.46
7.3.00.0000.01516.53
7.2.330.0120.00916.39
7.2.320.0090.00916.82
7.2.310.0060.01616.77
7.2.300.0080.00816.69
7.2.290.0060.01116.38
7.2.260.0070.01315.32
7.2.250.0060.01114.64
7.2.240.0070.01015.05
7.2.230.0070.01114.48
7.2.220.0130.00014.96
7.2.210.0120.00414.82
7.2.200.0040.00814.62
7.2.190.0000.01014.98
7.2.180.0070.01015.06
7.2.170.0030.01215.09
7.2.160.0030.01015.24
7.2.150.0070.01116.91
7.2.140.0060.00916.72
7.2.130.0070.00716.60
7.2.120.0090.00616.73
7.2.110.0070.01016.68
7.2.100.0100.00316.94
7.2.90.0100.00617.10
7.2.80.0000.01516.80
7.2.70.0090.00616.59
7.2.60.0090.00616.89
7.2.50.0000.01316.85
7.2.40.0030.01216.83
7.2.30.0080.00416.84
7.2.20.0060.01016.70
7.2.10.0030.01016.80
7.2.00.0050.01218.00
7.1.330.0070.01115.47
7.1.320.0100.00615.71
7.1.310.0070.01015.64
7.1.300.0000.01415.68
7.1.290.0160.00015.82
7.1.280.0100.00315.77
7.1.270.0060.00615.50
7.1.260.0130.00315.71
7.1.250.0070.00815.41
7.1.240.0100.00515.61
7.1.230.0090.00015.47
7.1.220.0100.00715.86
7.1.210.0060.00915.30
7.1.200.0080.00815.70
7.1.190.0000.01515.67
7.1.180.0040.00715.84
7.1.170.0060.00915.44
7.1.160.0000.01415.57
7.1.150.0070.00715.53
7.1.140.0030.01015.88
7.1.130.0040.01115.52
7.1.120.0060.00915.65
7.1.110.0030.01015.80
7.1.100.0430.00616.03
7.1.90.0000.01015.73
7.1.80.0090.00615.75
7.1.70.0060.00516.41
7.1.60.0100.00717.51
7.1.50.0110.00516.09
7.1.40.0070.00715.47
7.1.30.0060.00615.85
7.1.20.0070.00715.61
7.1.10.0060.00615.82
7.1.00.0020.02319.05
7.0.330.0040.01115.22
7.0.320.0040.01115.19
7.0.310.0040.00914.92
7.0.300.0090.00315.18
7.0.290.0070.00715.35
7.0.280.0000.01315.32
7.0.270.0030.01014.95
7.0.260.0030.00815.33
7.0.250.0040.00715.44
7.0.240.0030.00915.36
7.0.230.0070.00715.38
7.0.220.0070.01015.33
7.0.210.0030.01315.43
7.0.200.0040.00616.02
7.0.190.0030.01015.27
7.0.180.0080.00615.61
7.0.170.0090.00615.31
7.0.160.0000.01315.20
7.0.150.0060.00615.20
7.0.140.0020.04318.58
7.0.130.0070.00415.32
7.0.120.0030.01515.12
7.0.110.0060.00615.05
7.0.100.0060.00315.12
7.0.90.0040.01115.27
7.0.80.0060.00315.24
7.0.70.0110.00315.36
7.0.60.0060.04518.35
7.0.50.0030.04618.67
7.0.40.0020.04916.70
7.0.30.0050.04816.66
7.0.20.0040.04716.67
7.0.10.0090.04316.67
7.0.00.0070.04516.62
5.6.400.0090.00614.20
5.6.390.0110.00414.41
5.6.380.0030.01013.90
5.6.370.0030.00614.23
5.6.360.0100.00314.32
5.6.350.0060.00614.03
5.6.340.0030.01013.91
5.6.330.0030.01013.89
5.6.320.0060.00313.89
5.6.310.0040.00814.29
5.6.300.0090.00314.37
5.6.290.0040.01114.31
5.6.280.0000.04717.41
5.6.270.0030.01513.98
5.6.260.0040.00714.20
5.6.250.0030.01214.29
5.6.240.0070.01013.91
5.6.230.0070.00414.16
5.6.220.0090.00614.27
5.6.210.0100.04017.40
5.6.200.0050.04617.55
5.6.190.0030.03917.53
5.6.180.0070.03817.48
5.6.170.0050.04317.54
5.6.160.0020.05017.70
5.6.150.0020.04817.66
5.6.140.0100.03317.64
5.6.130.0030.04417.55
5.6.120.0020.04817.42
5.6.110.0070.04517.59
5.6.100.0050.04517.65
5.6.90.0080.04517.71
5.6.80.0050.04117.24
5.6.70.0020.04517.22
5.6.60.0020.04017.14
5.6.50.0030.04517.29
5.6.40.0050.04217.27
5.6.30.0070.03717.21
5.6.20.0040.02917.40
5.6.10.0020.04017.46
5.6.00.0050.02317.27
5.5.380.0000.01614.10
5.5.370.0040.01114.23
5.5.360.0000.01213.85
5.5.350.0070.03917.21
5.5.340.0010.05217.26
5.5.330.0070.04317.44
5.5.320.0090.03917.47
5.5.310.0080.04217.58
5.5.300.0000.04717.37
5.5.290.0070.04217.50
5.5.280.0020.04617.39
5.5.270.0070.04517.47
5.5.260.0100.04317.48
5.5.250.0080.03717.37
5.5.240.0050.04717.17
5.5.230.0030.04317.14
5.5.220.0060.04117.05
5.5.210.0070.03917.15
5.5.200.0100.03717.07
5.5.190.0070.04217.14
5.5.180.0070.04217.27
5.5.170.0030.01014.07
5.5.160.0070.03816.90
5.5.150.0090.02216.93
5.5.140.0050.02017.01
5.5.130.0050.02617.05
5.5.120.0030.02516.99
5.5.110.0020.04717.24
5.5.100.0040.02716.97
5.5.90.0040.02216.95
5.5.80.0080.04817.07
5.5.70.0080.02817.13
5.5.60.0030.04716.93
5.5.50.0030.02817.21
5.5.40.0050.03316.83
5.5.30.0050.04217.08
5.5.20.0020.04416.98
5.5.10.0050.03817.01
5.5.00.0050.03016.98
5.4.450.0020.04315.19
5.4.440.0050.03015.24
5.4.430.0000.04615.24
5.4.420.0070.03715.17
5.4.410.0040.04115.04
5.4.400.0100.03514.95
5.4.390.0040.04415.16
5.4.380.0020.04114.96
5.4.370.0050.03015.05
5.4.360.0070.04115.07
5.4.350.0040.03914.86
5.4.340.0020.03015.01
5.4.330.0030.00310.82
5.4.320.0020.03014.93
5.4.310.0050.02015.00
5.4.300.0030.01815.11
5.4.290.0050.02514.93
5.4.280.0050.03014.93
5.4.270.0030.02214.79
5.4.260.0080.03314.81
5.4.250.0050.02514.85
5.4.240.0020.03214.98
5.4.230.0070.03515.08
5.4.220.0060.04014.92
5.4.210.0060.03514.89
5.4.200.0040.03514.92
5.4.190.0070.03615.12
5.4.180.0080.03214.93
5.4.170.0060.03915.02
5.4.160.0020.04714.83
5.4.150.0050.04114.79
5.4.140.0050.03913.77
5.4.130.0050.03713.74
5.4.120.0040.03913.67
5.4.110.0000.04013.69
5.4.100.0050.03513.61
5.4.90.0030.04213.63
5.4.80.0030.03313.54
5.4.70.0040.03513.71
5.4.60.0030.04213.58
5.4.50.0000.03813.63
5.4.40.0020.03713.64
5.4.30.0030.03713.70
5.4.20.0030.04013.76
5.4.10.0100.01713.60
5.4.00.0040.02513.32
5.3.290.0030.03714.70
5.3.280.0070.07714.57
5.3.270.0100.05714.48
5.3.260.0000.04714.59
5.3.250.0070.05714.59
5.3.240.0030.06714.73
5.3.230.0000.06314.48
5.3.220.0000.08014.61
5.3.210.0030.08014.50
5.3.200.0000.07714.63
5.3.190.0030.07314.65
5.3.180.0000.05014.63
5.3.170.0030.07314.57
5.3.160.0070.07014.60
5.3.150.0070.07014.63
5.3.140.0000.08014.54
5.3.130.0170.06014.62
5.3.120.0100.06314.53
5.3.110.0030.06714.67
5.3.100.0070.07014.16
5.3.90.0030.07014.09
5.3.80.0030.07713.94
5.3.70.0000.06713.91
5.3.60.0070.07014.01
5.3.50.0030.07313.88
5.3.40.0000.06013.86
5.3.30.0000.08013.94
5.3.20.0070.06313.79
5.3.10.0100.06013.66
5.3.00.0070.06013.68
5.2.170.0100.06011.23
5.2.160.0030.05311.02
5.2.150.0030.06011.23
5.2.140.0030.06311.20
5.2.130.0000.06011.14
5.2.120.0030.06011.13
5.2.110.0030.05311.23
5.2.100.0030.03311.18
5.2.90.0000.03711.17
5.2.80.0000.03011.22
5.2.70.0000.03011.12
5.2.60.0000.03011.04
5.2.50.0030.02711.09
5.2.40.0030.02711.07
5.2.30.0000.03011.04
5.2.20.0030.02710.83
5.2.10.0000.02310.73
5.2.00.0000.03010.74
5.1.60.0000.02310.44
5.1.50.0030.02310.44
5.1.40.0000.02710.44
5.1.30.0000.02710.44
5.1.20.0000.03010.47
5.1.10.0000.06010.44
5.1.00.0070.05010.44
5.0.50.0030.04010.44
5.0.40.0000.03310.44
5.0.30.0000.04010.44
5.0.20.0000.02010.44
5.0.10.0000.02310.44
5.0.00.0000.03010.44
4.4.90.0000.01310.44
4.4.80.0000.02010.44
4.4.70.0000.01310.44
4.4.60.0000.01710.44
4.4.50.0000.01310.44
4.4.40.0000.02310.44
4.4.30.0000.01710.44
4.4.20.0030.03310.44
4.4.10.0030.01310.44
4.4.00.0030.04710.44
4.3.110.0000.01710.44
4.3.100.0000.03710.44
4.3.90.0030.01010.44
4.3.80.0000.02710.44
4.3.70.0000.01710.44
4.3.60.0030.01710.44
4.3.50.0000.02010.44
4.3.40.0000.02010.44
4.3.30.0000.01710.44
4.3.20.0000.01710.44
4.3.10.0000.01710.44
4.3.00.0030.01010.44

preferences:
58.28 ms | 401 KiB | 5 Q