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 = msubstr($a,0,5); 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.0150.00316.63
8.3.50.0200.01317.26
8.3.40.0120.00318.70
8.3.30.0130.00618.63
8.3.20.0130.00618.73
8.3.10.0170.00320.31
8.3.00.0060.01319.13
8.2.180.0140.00716.75
8.2.170.0090.00922.96
8.2.160.0160.00321.07
8.2.150.0040.00424.18
8.2.140.0170.00024.66
8.2.130.0140.00426.16
8.2.120.0080.01119.48
8.2.110.0070.00321.04
8.2.100.0120.00017.64
8.2.90.0040.00417.75
8.2.80.0050.00317.97
8.2.70.0050.00317.80
8.2.60.0030.00617.80
8.2.50.0000.00818.10
8.2.40.0060.00620.28
8.2.30.0030.00518.01
8.2.20.0000.00717.61
8.2.10.0080.00017.77
8.2.00.0040.00417.64
8.1.280.0030.01425.92
8.1.270.0070.00024.66
8.1.260.0150.00426.35
8.1.250.0130.00728.09
8.1.240.0090.00022.06
8.1.230.0080.00319.00
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0070.00417.36
8.1.190.0040.00417.23
8.1.180.0080.00018.10
8.1.170.0060.00318.71
8.1.160.0090.00018.90
8.1.150.0080.00018.63
8.1.140.0070.00017.38
8.1.130.0070.00017.71
8.1.120.0000.00917.43
8.1.110.0040.00417.50
8.1.100.0040.00417.49
8.1.90.0040.00417.38
8.1.80.0000.00717.39
8.1.70.0030.00317.48
8.1.60.0040.00417.59
8.1.50.0000.00717.39
8.1.40.0000.00817.55
8.1.30.0030.00517.66
8.1.20.0060.00317.56
8.1.10.0050.00317.55
8.1.00.0080.00417.47
8.0.300.0080.00018.78
8.0.290.0040.00416.88
8.0.280.0030.00318.56
8.0.270.0060.00316.95
8.0.260.0070.00016.92
8.0.250.0050.00216.96
8.0.240.0040.00417.01
8.0.230.0000.00716.98
8.0.220.0060.00317.01
8.0.210.0000.00917.07
8.0.200.0030.00316.98
8.0.190.0000.00717.09
8.0.180.0100.00017.08
8.0.170.0090.00016.99
8.0.160.0000.00717.12
8.0.150.0030.00616.86
8.0.140.0120.00016.99
8.0.130.0000.00613.42
8.0.120.0000.00817.02
8.0.110.0000.00716.91
8.0.100.0000.00717.05
8.0.90.0040.00416.98
8.0.80.0060.01017.07
8.0.70.0000.00717.05
8.0.60.0000.00716.98
8.0.50.0050.00317.03
8.0.30.0090.00917.00
8.0.20.0090.01017.21
8.0.10.0020.00516.91
8.0.00.0130.00816.70
7.4.330.0050.00012.99
7.4.320.0000.00816.61
7.4.300.0030.00316.65
7.4.290.0070.00016.62
7.4.280.0080.00016.66
7.4.270.0030.00316.50
7.4.260.0040.00413.27
7.4.250.0090.00016.61
7.4.240.0040.00416.62
7.4.230.0030.00316.35
7.4.220.0170.00316.70
7.4.210.0090.00516.57
7.4.200.0070.00016.51
7.4.190.0040.00416.70
7.4.160.0100.00516.73
7.4.150.0160.00316.58
7.4.140.0090.00816.59
7.4.130.0110.00616.44
7.4.120.0100.00716.55
7.4.110.0170.00716.57
7.4.100.0110.00716.58
7.4.90.0060.01216.49
7.4.80.0120.01019.39
7.4.70.0130.00316.62
7.4.60.0080.00816.55
7.4.50.0060.00316.19
7.4.40.0030.01016.55
7.4.30.0100.01016.59
7.4.00.0070.00714.99
7.3.330.0060.00013.28
7.3.320.0000.00613.22
7.3.310.0040.00416.36
7.3.300.0030.00316.21
7.3.290.0030.01216.21
7.3.280.0090.00616.29
7.3.270.0070.01016.56
7.3.260.0180.00316.20
7.3.250.0070.01116.54
7.3.240.0160.00016.64
7.3.230.0030.01416.59
7.3.210.0140.00316.35
7.3.200.0060.01016.32
7.3.190.0080.01216.50
7.3.180.0130.00316.30
7.3.170.0130.00616.60
7.3.160.0070.00716.41
7.3.120.0110.00414.88
7.2.330.0110.00716.54
7.2.320.0070.01116.75
7.2.310.0040.01916.70
7.2.300.0130.00316.70
7.2.290.0140.00316.64
7.2.00.0040.00819.28
7.1.100.0070.00418.04
7.1.70.0000.00817.17
7.1.60.0070.01719.40
7.1.50.0070.01317.11
7.1.00.0030.07022.45
7.0.200.0040.00416.95
7.0.140.0000.07322.09
7.0.120.0070.07022.01
7.0.60.0100.05019.88
7.0.50.0200.06017.90
7.0.40.0130.07320.23
7.0.30.0330.03320.26
7.0.20.0300.07720.23
7.0.10.0130.08320.36
7.0.00.0030.05720.05
5.6.210.0100.07320.63
5.6.200.0030.07718.18
5.6.190.0030.07020.34
5.6.180.0230.05020.38
5.6.170.0300.06720.62
5.6.160.0070.07720.51
5.6.150.0030.06718.21
5.6.140.0070.04018.19
5.6.130.0070.08018.21
5.6.120.0030.09020.90
5.6.110.0130.08020.97
5.6.100.0030.04021.02
5.6.90.0130.04021.14
5.6.80.0030.04020.41
5.5.350.3470.03320.53
5.5.340.0000.06018.08
5.5.330.0030.08020.53
5.5.320.0200.04720.36
5.5.310.0230.04020.35
5.5.300.0030.05317.92
5.5.290.0100.08018.02
5.5.280.0030.04720.97
5.5.270.0070.04320.77
5.5.260.0200.04720.86
5.5.250.0100.07720.61
5.5.240.0130.07320.24
5.4.450.0230.06319.31
5.4.440.0230.08019.27
5.4.430.0300.06719.29
5.4.420.0270.07719.31
5.4.410.0270.05019.43
5.4.400.0230.06319.23
5.4.390.0300.06319.19
5.4.380.0230.07019.24
5.4.370.0300.06019.25
5.4.360.0400.06719.12
5.4.350.0370.06318.98
5.4.340.0230.07018.95
5.4.320.0270.04719.09
5.4.310.0230.06319.09
5.4.300.0170.04019.19
5.4.290.0130.04718.84
5.4.280.0430.05719.22
5.4.270.0330.03719.12
5.4.260.0370.04019.21
5.4.250.0230.07019.07
5.4.240.0270.05319.13
5.4.230.0270.07019.07
5.4.220.0230.07318.86
5.4.210.0300.04019.19
5.4.200.0300.06719.09
5.4.190.0200.04319.30
5.4.180.0170.06319.01
5.4.170.0230.03719.08
5.4.160.0170.08019.20
5.4.150.0230.06719.20
5.4.140.0230.03316.35
5.4.130.0230.06716.50
5.4.120.0270.06016.34
5.4.110.0170.05716.56
5.4.100.0270.06016.25
5.4.90.0330.04316.59
5.4.80.0130.04016.52
5.4.70.0230.07016.55
5.4.60.0200.03316.49
5.4.50.0170.06716.51
5.4.40.0100.05716.23
5.4.30.0270.03716.53
5.4.20.0230.06016.37
5.4.10.0270.05016.43
5.4.00.0200.05715.95
5.3.290.0200.07314.73
5.3.280.0200.03714.50
5.3.270.0130.04314.75
5.3.260.0200.05014.53
5.3.250.0230.03014.66
5.3.240.0230.07014.75
5.3.230.0200.04314.56
5.3.220.0270.06714.57
5.3.210.0230.04714.55
5.3.200.0230.04714.54
5.3.190.0300.03714.50
5.3.180.0200.06714.53
5.3.170.0270.07014.57
5.3.160.0230.05014.55
5.3.150.0130.04314.47
5.3.140.0170.03714.47
5.3.130.0200.05014.69
5.3.120.0270.06714.77
5.3.110.0370.03714.52
5.3.100.0330.06314.15
5.3.90.0300.05314.07
5.3.80.0200.08014.10
5.3.70.0230.03313.91
5.3.60.0100.04313.91
5.3.50.0230.03014.00
5.3.40.0270.05014.19
5.3.30.0170.04713.96
5.3.20.0230.06013.62
5.3.10.0130.03713.73
5.3.00.0270.06313.70
5.2.170.0200.03312.50
5.2.160.0170.05012.50
5.2.150.0200.03012.50
5.2.140.0200.06012.50
5.2.130.0130.03012.50
5.2.120.0130.03712.50
5.2.110.0200.04712.50
5.2.100.0200.03712.50
5.2.90.0270.05012.50
5.2.80.0270.05712.50
5.2.70.0200.03712.50
5.2.60.0200.05312.50
5.2.50.0130.06312.50
5.2.40.0130.04712.50
5.2.30.0170.05312.50
5.2.20.0200.05012.50
5.2.10.0170.05712.50
5.2.00.0200.03012.50
5.1.60.0200.05312.50
5.1.50.0170.03012.50
5.1.40.0230.04312.50
5.1.30.0170.04312.50
5.1.20.0200.04312.50
5.1.10.0170.03012.50
5.1.00.0200.02712.50
5.0.50.0070.04312.50
5.0.40.0130.02012.50
5.0.30.0070.05312.50
5.0.20.0000.02712.50
5.0.10.0070.02712.50
5.0.00.0070.03012.50
4.4.90.0130.01012.50
4.4.80.0030.02312.50
4.4.70.0070.02012.50
4.4.60.0070.01712.50
4.4.50.0100.01712.50
4.4.40.0070.02312.50
4.4.30.0030.01712.50
4.4.20.0100.01312.50
4.4.10.0100.02012.50
4.4.00.0170.04312.50
4.3.110.0170.02312.50
4.3.100.0130.01712.50
4.3.90.0070.02012.50
4.3.80.0100.05012.50
4.3.70.0070.02712.50
4.3.60.0100.01712.50
4.3.50.0100.03712.50
4.3.40.0070.03012.50
4.3.30.0070.02012.50
4.3.20.0000.02012.50
4.3.10.0070.03312.50
4.3.00.0030.03012.50

preferences:
70.89 ms | 400 KiB | 5 Q