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 csubstr($str, $start=0, $length, $charset="utf-8", $suffix=true) { if(function_exists("mb_substr")) return mb_substr($str, $start, $length, $charset); $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)); if($suffix) return $slice."…"; return $slice; } $a = '测试这是一个测试'; //$a = 'xxxxbbbbbnnn'; $b = csubstr($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.40.0080.01118.67
8.3.30.0070.01518.72
8.3.20.0110.00318.83
8.3.10.0030.00520.39
8.3.00.0080.00021.73
8.2.170.0130.00322.96
8.2.160.0070.00720.39
8.2.150.0050.00324.18
8.2.140.0110.00324.66
8.2.130.0040.00426.16
8.2.120.0040.00420.93
8.2.110.0070.00420.39
8.2.100.0090.00317.78
8.2.90.0040.00419.09
8.2.80.0060.00317.97
8.2.70.0130.00017.50
8.2.60.0060.00317.80
8.2.50.0040.00418.10
8.2.40.0090.00018.03
8.2.30.0000.00819.77
8.2.20.0040.00417.54
8.2.10.0050.00319.46
8.2.00.0100.00017.77
8.1.270.0070.00023.99
8.1.260.0080.00026.35
8.1.250.0060.00928.09
8.1.240.0070.00322.10
8.1.230.0040.00817.83
8.1.220.0050.00317.74
8.1.210.0080.00018.77
8.1.200.0030.00617.35
8.1.190.0000.00817.23
8.1.180.0060.00318.10
8.1.170.0090.00018.54
8.1.160.0000.00718.80
8.1.150.0030.00518.60
8.1.140.0080.00017.34
8.1.130.0030.00317.81
8.1.120.0030.00517.43
8.1.110.0020.00517.44
8.1.100.0030.00517.47
8.1.90.0040.00417.46
8.1.80.0040.00417.42
8.1.70.0040.00417.35
8.1.60.0030.00517.50
8.1.50.0020.00517.54
8.1.40.0040.00417.52
8.1.30.0000.00717.79
8.1.20.0000.00817.64
8.1.10.0070.00017.54
8.1.00.0080.00017.45
8.0.300.0040.00418.77
8.0.290.0040.00416.75
8.0.280.0080.00018.41
8.0.270.0000.00817.20
8.0.260.0030.00316.84
8.0.250.0000.00817.05
8.0.240.0040.00717.01
8.0.230.0040.00417.05
8.0.220.0000.00716.83
8.0.210.0030.00316.93
8.0.200.0030.00317.03
8.0.190.0030.00516.96
8.0.180.0000.00717.02
8.0.170.0000.00716.99
8.0.160.0080.00017.06
8.0.150.0030.00716.94
8.0.140.0000.00716.98
8.0.130.0020.00513.43
8.0.120.0040.00416.90
8.0.110.0000.00716.86
8.0.100.0040.00416.86
8.0.90.0040.00416.85
8.0.80.0070.01416.87
8.0.70.0000.00716.99
8.0.60.0040.00417.00
8.0.50.0030.00516.99
8.0.30.0130.00617.09
8.0.20.0130.00517.40
8.0.10.0000.00717.11
8.0.00.0120.00916.62
7.4.330.0030.00314.77
7.4.320.0040.00416.47
7.4.300.0000.00616.59
7.4.290.0050.00316.59
7.4.280.0030.00516.55
7.4.270.0000.00716.72
7.4.260.0060.00013.30
7.4.250.0040.00416.41
7.4.240.0040.00416.56
7.4.230.0030.00316.54
7.4.220.0060.01216.57
7.4.210.0050.01116.64
7.4.200.0000.00716.63
7.4.190.0040.00416.52
7.4.160.0150.00316.34
7.4.150.0060.01317.40
7.4.140.0150.00617.86
7.4.130.0120.00716.42
7.4.120.0110.00716.51
7.4.110.0080.01016.58
7.4.100.0120.00616.46
7.4.90.0030.01416.43
7.4.80.0030.01419.37
7.4.70.0110.00616.50
7.4.60.0130.00316.41
7.4.50.0070.00416.32
7.4.40.0000.01622.27
7.4.30.0090.00916.55
7.4.10.0110.01116.29
7.4.00.0110.00615.67
7.3.330.0000.00513.27
7.3.320.0000.00513.20
7.3.310.0070.00016.27
7.3.300.0000.00616.19
7.3.290.0130.00016.21
7.3.280.0100.00516.17
7.3.270.0070.01017.40
7.3.260.0110.00618.24
7.3.250.0080.02916.27
7.3.240.0090.00616.27
7.3.230.0130.00816.39
7.3.210.0130.00716.65
7.3.200.0110.00619.39
7.3.190.0090.00916.23
7.3.180.0030.01316.52
7.3.170.0100.00716.27
7.3.160.0080.00816.50
7.3.130.0090.00916.28
7.3.120.0020.01415.41
7.3.110.0100.00716.10
7.3.100.0150.00016.27
7.3.90.0040.01116.22
7.3.80.0070.00716.18
7.3.70.0090.00616.28
7.3.60.0060.00316.26
7.3.50.0030.00916.03
7.3.40.0130.00316.19
7.3.30.0050.00516.31
7.3.20.0070.00718.06
7.3.10.0030.01018.19
7.3.00.0050.01018.19
7.2.330.0110.01116.30
7.2.320.0110.01116.32
7.2.310.0090.00916.70
7.2.300.0070.01016.72
7.2.290.0070.01016.54
7.2.260.0160.00316.62
7.2.250.0070.01416.35
7.2.240.0060.00616.52
7.2.230.0070.01016.65
7.2.220.0140.00316.50
7.2.210.0100.00716.37
7.2.200.0100.00316.61
7.2.190.0070.00716.45
7.2.180.0070.00716.55
7.2.170.0090.00616.53
7.2.160.0060.00316.51
7.2.150.0070.01018.24
7.2.140.0120.00318.38
7.2.130.0040.01118.28
7.2.120.0030.01418.32
7.2.110.0000.01018.09
7.2.100.0080.00818.41
7.2.90.0040.00718.14
7.2.80.0070.00718.43
7.2.70.0090.00618.11
7.2.60.0030.01318.30
7.2.50.0100.00018.17
7.2.40.0100.00718.36
7.2.30.0040.01118.31
7.2.20.0110.00318.28
7.2.10.0000.01518.28
7.2.00.0070.00718.65
7.1.330.0110.00417.36
7.1.320.0070.00717.27
7.1.310.0060.00917.23
7.1.300.0030.00617.47
7.1.290.0070.01017.32
7.1.280.0120.00017.30
7.1.270.0070.00717.30
7.1.260.0090.00617.24
7.1.250.0030.01317.23
7.1.240.0070.00717.29
7.1.230.0090.00617.15
7.1.220.0110.00417.18
7.1.210.0060.00917.18
7.1.200.0090.00317.32
7.1.190.0060.00617.23
7.1.180.0000.01117.14
7.1.170.0030.01017.28
7.1.160.0090.00917.21
7.1.150.0100.00317.13
7.1.140.0120.00317.23
7.1.130.0100.00717.33
7.1.120.0030.01317.13
7.1.110.0090.00317.36
7.1.100.0030.01017.76
7.1.90.0030.00617.21
7.1.80.0070.00717.37
7.1.70.0030.00517.08
7.1.60.0050.01618.36
7.1.50.0050.01417.08
7.1.40.0100.00317.29
7.1.30.0090.00317.42
7.1.20.0070.00717.32
7.1.10.0070.00717.41
7.1.00.0030.03719.79
7.0.330.0000.01217.03
7.0.320.0000.01316.94
7.0.310.0000.01417.00
7.0.300.0070.00316.88
7.0.290.0070.00716.86
7.0.280.0040.00716.93
7.0.270.0070.01017.14
7.0.260.0040.00416.78
7.0.250.0030.01017.09
7.0.240.0120.00317.11
7.0.230.0070.00717.03
7.0.220.0000.01517.09
7.0.210.0100.00316.96
7.0.200.0060.00616.90
7.0.190.0070.01117.24
7.0.180.0100.00316.84
7.0.170.0090.00316.96
7.0.160.0000.01417.18
7.0.150.0120.00316.79
7.0.140.0080.03819.44
7.0.130.0080.00617.05
7.0.120.0030.01517.06
7.0.110.0060.00817.00
7.0.100.0060.00616.88
7.0.90.0040.00816.85
7.0.80.0100.00316.80
7.0.70.0080.00817.01
7.0.60.0070.03718.53
7.0.50.0120.03217.37
7.0.40.0030.03316.33
7.0.30.0000.04816.33
7.0.20.0100.03916.30
7.0.10.0080.03916.31
7.0.00.0030.04216.32
5.6.400.0160.00315.41
5.6.390.0030.00715.48
5.6.380.0120.00315.73
5.6.370.0060.00915.88
5.6.360.0120.00315.80
5.6.350.0030.01015.50
5.6.340.0080.00315.93
5.6.330.0070.00315.66
5.6.320.0030.00615.93
5.6.310.0060.00915.70
5.6.300.0030.01215.92
5.6.290.0030.00915.79
5.6.280.0030.04318.33
5.6.270.0100.01016.12
5.6.260.0070.01115.88
5.6.250.0030.00715.81
5.6.240.0060.00615.79
5.6.230.0080.00815.82
5.6.220.0040.01116.01
5.6.210.0070.04018.24
5.6.200.0120.04417.00
5.6.190.0070.02517.05
5.6.180.0080.04116.97
5.6.170.0050.04516.90
5.6.160.0080.04116.87
5.6.150.0050.02317.19
5.6.140.0020.03816.99
5.6.130.0090.04217.12
5.6.120.0030.02517.05
5.6.110.0080.02016.95
5.6.100.0040.02416.98
5.6.90.0080.02016.92
5.6.80.0030.02316.71
5.6.70.0080.02016.60
5.6.60.0060.02316.78
5.6.50.0030.02516.50
5.6.40.0040.02616.65
5.6.30.0070.01916.60
5.6.20.0020.02416.66
5.6.10.0050.02216.61
5.6.00.0090.02416.66
5.5.380.0080.00815.88
5.5.370.0030.01015.73
5.5.360.0030.00915.94
5.5.350.0100.04218.09
5.5.340.0100.03816.78
5.5.330.0050.03216.76
5.5.320.0050.03116.85
5.5.310.0030.03216.87
5.5.300.0030.03116.80
5.5.290.0070.04316.86
5.5.280.0040.02216.88
5.5.270.0080.02116.83
5.5.260.0090.02016.87
5.5.250.0030.02516.73
5.5.240.0080.02116.52
5.5.230.0000.03016.55
5.5.220.0070.02416.52
5.5.210.0020.02716.48
5.5.200.0030.02516.46
5.5.190.0030.02416.54
5.5.180.0070.02216.60
5.5.170.0060.00915.66
5.5.160.0050.02216.46
5.5.150.0080.01816.49
5.5.140.0020.02616.45
5.5.130.0030.02516.29
5.5.120.0070.02016.53
5.5.110.0080.02016.54
5.5.100.0030.02516.45
5.5.90.0020.03416.32
5.5.80.0070.02316.43
5.5.70.0050.04316.52
5.5.60.0050.04316.48
5.5.50.0090.04016.48
5.5.40.0090.03916.34
5.5.30.0030.04516.40
5.5.20.0050.04516.48
5.5.10.0070.04216.35
5.5.00.0070.04316.34
5.4.450.0050.04315.98
5.4.440.0060.02316.10
5.4.430.0070.02015.97
5.4.420.0070.01815.93
5.4.410.0060.02315.85
5.4.400.0050.02015.68
5.4.390.0030.02415.67
5.4.380.0050.01815.70
5.4.370.0070.02215.80
5.4.360.0020.02815.75
5.4.350.0050.01915.69
5.4.340.0070.01815.78
5.4.330.0150.00012.46
5.4.320.0070.02215.70
5.4.310.0070.01915.81
5.4.300.0020.02315.73
5.4.290.0080.01815.78
5.4.280.0030.02215.76
5.4.270.0020.02415.88
5.4.260.0030.02315.80
5.4.250.0060.01915.73
5.4.240.0030.02315.81
5.4.230.0070.01815.82
5.4.220.0020.03215.76
5.4.210.0030.02315.75
5.4.200.0050.03715.72
5.4.190.0080.04315.90
5.4.180.0100.03315.80
5.4.170.0070.03915.70
5.4.160.0070.03915.88
5.4.150.0020.02715.62
5.4.140.0030.03514.49
5.4.130.0080.03814.43
5.4.120.0070.03014.49
5.4.110.0070.04114.47
5.4.100.0070.02314.54
5.4.90.0080.02514.58
5.4.80.0060.02814.27
5.4.70.0090.03714.43
5.4.60.0050.02514.44
5.4.50.0080.03614.53
5.4.40.0050.03314.41
5.4.30.0070.03814.46
5.4.20.0050.03714.53
5.4.10.0060.04314.48
5.4.00.0080.04014.20
5.3.290.0070.02114.01
5.3.280.0050.02613.78
5.3.270.0030.04013.93
5.3.260.0090.03713.96
5.3.250.0100.02713.95
5.3.240.0040.04913.78
5.3.230.0100.04213.78
5.3.220.0110.03613.71
5.3.210.0100.04313.79
5.3.200.0130.03813.73
5.3.190.0110.04213.75
5.3.180.0090.02613.79
5.3.170.0130.03813.74
5.3.160.0030.03013.83
5.3.150.0110.04013.79
5.3.140.0050.04013.79
5.3.130.0070.04413.75
5.3.120.0090.03513.83
5.3.110.0120.02213.79
5.3.100.0060.04413.53
5.3.90.0110.02313.64
5.3.80.0090.02113.42
5.3.70.0090.03813.56
5.3.60.0100.04213.63
5.3.50.0050.04013.40
5.3.40.0070.04213.39
5.3.30.0080.02513.57
5.3.20.0110.02013.25
5.3.10.0070.03713.11
5.3.00.0070.03213.20
5.2.170.0070.06011.23
5.2.160.0030.06011.25
5.2.150.0000.04311.05
5.2.140.0030.03011.00
5.2.130.0030.05011.13
5.2.120.0070.06311.16
5.2.110.0070.06011.16
5.2.100.0030.05711.08
5.2.90.0070.06011.14
5.2.80.0030.06710.99
5.2.70.0000.05311.07
5.2.60.0030.04311.10
5.2.50.0030.06010.87
5.2.40.0000.04311.04
5.2.30.0070.06010.99
5.2.20.0070.04011.03
5.2.10.0030.03310.90
5.2.00.0000.04010.80
5.1.60.0030.03310.00
5.1.50.0070.0439.95
5.1.40.0070.05010.06
5.1.30.0030.06010.23
5.1.20.0030.04310.58
5.1.10.0000.06310.07
5.1.00.0070.05710.07
5.0.50.0070.0479.45
5.0.40.0100.0409.45
5.0.30.0130.0579.45
5.0.20.0000.0379.45
5.0.10.0070.0409.45
5.0.00.0030.0509.45
4.4.90.0000.0309.45
4.4.80.0070.0309.45
4.4.70.0070.0109.45
4.4.60.0000.0209.45
4.4.50.0000.0339.45
4.4.40.0000.0309.45
4.4.30.0000.0239.45
4.4.20.0000.0209.45
4.4.10.0030.0309.45
4.4.00.0030.0609.45
4.3.110.0000.0379.45
4.3.100.0000.0409.45
4.3.90.0070.0339.45
4.3.80.0030.0539.45
4.3.70.0030.0309.45
4.3.60.0000.0239.45
4.3.50.0070.0209.45
4.3.40.0030.0339.45
4.3.30.0070.0339.45
4.3.20.0070.0339.45
4.3.10.0000.0309.45
4.3.00.0000.0279.45

preferences:
42.79 ms | 400 KiB | 5 Q