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; } $a = '测试这是一个测试'; //$a = 'xxxxbbbbbnnn'; $b = mb_strcut($a,0,5,'gbk'); 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.40.0110.00718.89
8.3.30.0080.01318.75
8.3.20.0080.00018.60
8.3.10.0040.00420.53
8.3.00.0060.00617.22
8.2.170.0090.00622.96
8.2.160.0130.00722.43
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00419.89
8.2.110.0060.00322.41
8.2.100.0040.00818.09
8.2.90.0060.00318.09
8.2.80.0060.00317.97
8.2.70.0050.00517.63
8.2.60.0040.00417.93
8.2.50.0040.00418.07
8.2.40.0000.00718.34
8.2.30.0030.00519.96
8.2.20.0030.00717.66
8.2.10.0060.00317.77
8.2.00.0040.00417.75
8.1.270.0040.00423.99
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0060.00322.32
8.1.230.0040.00822.94
8.1.220.0030.00617.80
8.1.210.0070.00318.91
8.1.200.0090.00017.47
8.1.190.0040.00417.75
8.1.180.0050.00318.10
8.1.170.0000.00818.87
8.1.160.0070.00018.96
8.1.150.0080.00018.62
8.1.140.0040.00417.45
8.1.130.0000.00717.97
8.1.120.0070.00017.43
8.1.110.0000.00717.51
8.1.100.0050.00217.52
8.1.90.0000.00717.48
8.1.80.0030.00317.36
8.1.70.0000.00717.38
8.1.60.0000.00717.58
8.1.50.0000.00717.61
8.1.40.0000.00717.55
8.1.30.0080.00017.68
8.1.20.0000.00817.74
8.1.10.0060.00317.61
8.1.00.0000.00717.48
8.0.300.0000.00720.17
8.0.290.0040.00416.75
8.0.280.0030.00318.52
8.0.270.0070.00017.44
8.0.260.0000.00616.87
8.0.250.0030.00616.99
8.0.240.0060.00317.07
8.0.230.0070.00017.13
8.0.220.0030.00617.05
8.0.210.0040.00316.98
8.0.200.0000.00717.07
8.0.190.0000.00817.13
8.0.180.0070.00416.95
8.0.170.0090.00016.93
8.0.160.0040.00416.99
8.0.150.0060.00317.05
8.0.140.0080.00016.87
8.0.130.0030.00313.45
8.0.120.0000.00717.02
8.0.110.0040.00416.96
8.0.100.0040.00417.01
8.0.90.0030.00616.94
8.0.80.0060.00916.91
8.0.70.0080.00017.09
8.0.60.0070.00016.80
8.0.50.0050.00316.91
8.0.30.0080.01117.03
8.0.20.0130.00617.40
8.0.10.0070.00016.95
8.0.00.0210.01616.64
7.4.330.0030.00314.72
7.4.320.0040.00416.44
7.4.300.0060.00016.53
7.4.290.0030.00716.46
7.4.280.0050.00316.50
7.4.270.0020.00516.49
7.4.260.0000.00613.29
7.4.250.0050.00316.35
7.4.240.0030.00516.62
7.4.230.0070.00016.51
7.4.220.0140.01016.45
7.4.210.0080.00916.60
7.4.200.0000.00716.49
7.4.190.0070.00016.78
7.4.160.0110.00416.52
7.4.150.0120.00617.40
7.4.140.0030.01317.22
7.4.130.0080.01016.47
7.4.120.0070.01016.38
7.4.110.0190.00316.20
7.4.100.0110.01116.46
7.4.90.0110.00716.49
7.4.80.0070.01119.03
7.4.70.0100.00716.64
7.4.60.0070.01016.70
7.4.50.0030.00516.57
7.4.40.0060.01322.27
7.4.30.0160.00316.38
7.4.00.0040.01215.07
7.3.330.0000.00713.25
7.3.320.0030.00313.07
7.3.310.0070.00016.26
7.3.300.0030.00316.10
7.3.290.0060.00916.20
7.3.280.0060.00816.25
7.3.270.0030.01317.40
7.3.260.0090.01418.24
7.3.250.0090.01216.46
7.3.240.0030.01716.44
7.3.230.0030.01316.51
7.3.210.0100.01016.45
7.3.200.0070.01019.39
7.3.190.0180.00616.34
7.3.180.0170.00016.52
7.3.170.0170.00316.41
7.3.160.0030.01316.27
7.3.120.0060.00914.47
7.2.330.0130.00416.39
7.2.320.0060.01216.30
7.2.310.0060.01216.58
7.2.300.0050.01116.50
7.2.290.0070.01816.52
7.2.60.0070.00716.74
7.1.200.0060.00615.52
7.1.70.0070.00717.02
7.1.60.0090.01519.40
7.1.50.0060.00616.97
7.1.00.0070.04022.40
7.0.200.0030.00816.56
7.0.140.0070.07021.95
7.0.60.0370.07019.93
7.0.50.0030.08317.86
7.0.40.0130.03720.20
7.0.30.0000.05020.26
7.0.20.0130.07020.02
7.0.10.0030.05720.26
7.0.00.0130.03320.21
5.6.280.0100.06720.91
5.6.210.0070.06720.61
5.6.200.0130.07318.18
5.6.190.0100.06320.61
5.6.180.0070.04020.57
5.6.170.0030.05020.41
5.6.160.0130.07320.38
5.6.150.0070.07320.41
5.6.140.0100.07320.50
5.6.130.0100.05320.17
5.6.120.0070.05320.42
5.6.110.0030.08320.50
5.6.100.0070.04020.32
5.6.90.0100.04020.15
5.6.80.0000.04319.71
5.6.70.0030.04019.81
5.6.60.0070.03719.91
5.6.50.0100.03319.89
5.6.40.0070.04019.76
5.6.30.0000.04319.73
5.6.20.0070.03719.75
5.6.10.0000.04319.68
5.6.00.0000.05319.52
5.5.350.0070.07320.43
5.5.340.0100.06317.93
5.5.330.0200.03720.31
5.5.320.0000.05720.35
5.5.310.0030.08720.25
5.5.300.0170.07020.12
5.5.290.0070.08320.29
5.5.280.0070.07020.20
5.5.270.0030.05020.29
5.5.260.0100.03720.12
5.5.250.0070.03719.79
5.5.240.0030.04019.59
5.5.230.0030.04019.68
5.5.220.0030.04019.36
5.5.210.0070.03719.35
5.5.200.0030.04019.56
5.5.190.0030.04019.47
5.5.180.0070.03719.59
5.5.160.0030.03719.66
5.5.150.0030.04019.64
5.5.140.0070.03719.55
5.5.130.0070.03719.58
5.5.120.0100.03719.28
5.5.110.0030.04019.46
5.5.100.0030.03719.59
5.5.90.0000.04319.21
5.5.80.0030.04019.37
5.5.70.0030.04019.22
5.5.60.0070.03319.37
5.5.50.0070.03719.48
5.5.40.0030.04019.38
5.5.30.0030.03719.48
5.5.20.0000.04319.47
5.5.10.0070.03719.37
5.5.00.0070.06319.41
5.4.450.0070.04319.20
5.4.440.0030.04319.47
5.4.430.0030.07019.26
5.4.420.0030.04019.19
5.4.410.0000.04319.18
5.4.400.0030.03718.87
5.4.390.0000.04019.15
5.4.380.0070.03319.20
5.4.370.0070.03719.26
5.4.360.0000.04019.25
5.4.350.0030.03718.85
5.4.340.0000.04019.14
5.4.320.0070.03318.86
5.4.310.0000.04019.15
5.4.300.0030.03719.20
5.4.290.0030.03719.08
5.4.280.0070.03319.23
5.4.270.0000.04019.24
5.4.260.0100.03019.25
5.4.250.0030.03719.14
5.4.240.0070.03319.26
5.4.230.0030.04018.84
5.4.220.0100.03319.15
5.4.210.0100.03019.23
5.4.200.0070.03319.15
5.4.190.0030.03719.23
5.4.180.0030.03719.14
5.4.170.0000.04318.91
5.4.160.0030.05018.85
5.4.150.0070.04018.90
5.4.140.0070.08316.50
5.4.130.0100.06316.39
5.4.120.0030.03716.29
5.4.110.0000.06716.28
5.4.100.0070.07016.45
5.4.90.0030.04716.39
5.4.80.0100.06016.39
5.4.70.0030.03716.32
5.4.60.0100.03016.65
5.4.50.0070.04016.38
5.4.40.0030.03716.50
5.4.30.0030.04016.36
5.4.20.0070.05716.27
5.4.10.0030.07016.27
5.4.00.0030.07015.84
5.3.290.0070.03314.66
5.3.280.0070.03714.63
5.3.270.0030.03714.75
5.3.260.0030.04314.66
5.3.250.0100.06714.52
5.3.240.0030.03714.63
5.3.230.0000.05014.64
5.3.220.0030.04014.64
5.3.210.0130.03714.57
5.3.200.0030.04014.58
5.3.190.0000.04314.73
5.3.180.0000.06314.55
5.3.170.0030.05714.62
5.3.160.0000.06014.57
5.3.150.0170.02314.56
5.3.140.0100.06714.61
5.3.130.0030.03714.56
5.3.120.0070.07314.57
5.3.110.0130.05014.54
5.3.100.0030.05014.10
5.3.90.0070.05013.96
5.3.80.0070.03314.09
5.3.70.0030.03714.09
5.3.60.0000.04014.16
5.3.50.0070.03313.98
5.3.40.0030.05713.95
5.3.30.0030.06013.96
5.3.20.0000.04313.85
5.3.10.0100.03013.69
5.3.00.0170.05313.72
5.2.170.0030.05311.15
5.2.160.0030.05011.18
5.2.150.0030.03011.30
5.2.140.0000.03311.14
5.2.130.0030.06011.18
5.2.120.0070.02311.02
5.2.110.0000.03710.99
5.2.100.0000.06711.10
5.2.90.0000.03311.24
5.2.80.0070.03311.01
5.2.70.0070.04711.13
5.2.60.0030.06011.21
5.2.50.0130.03711.06
5.2.40.0070.04711.05
5.2.30.0000.03710.96
5.2.20.0130.05311.01
5.2.10.0100.05011.02
5.2.00.0030.02710.61
5.1.60.0100.0479.96
5.1.50.0070.02010.03
5.1.40.0100.0439.96
5.1.30.0000.03010.23
5.1.20.0000.06010.34
5.1.10.0130.02010.07
5.1.00.0100.02010.06
5.0.50.0000.0308.62
5.0.40.0030.0208.49
5.0.30.0030.0408.22
5.0.20.0030.0378.18
5.0.10.0070.0408.16
5.0.00.0030.0408.24
4.4.90.0030.0177.49
4.4.80.0070.0307.49
4.4.70.0000.0277.49
4.4.60.0000.0207.49
4.4.50.0000.0177.49
4.4.40.0030.0407.49
4.4.30.0100.0337.49
4.4.20.0030.0207.49
4.4.10.0000.0177.49
4.4.00.0000.0437.49
4.3.110.0030.0177.49
4.3.100.0030.0377.49
4.3.90.0030.0207.49
4.3.80.0000.0537.49
4.3.70.0000.0237.49
4.3.60.0030.0177.49
4.3.50.0030.0337.49
4.3.40.0030.0337.49
4.3.30.0030.0277.49
4.3.20.0000.0337.49
4.3.10.0000.0177.49
4.3.00.0070.0337.49

preferences:
39.53 ms | 400 KiB | 5 Q