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 GBsubstr($string, $start, $length) { if(strlen($string)>$length){ $str=null; $len=$start+$length; for($i=$start;$i<$len;$i++){ if(ord(substr($string,$i,1))>0xa0){ $str.=substr($string,$i,2); $i++; }else{ $str.=substr($string,$i,1); } } return $str.'...'; }else{ return $string; } } $a = '测试这是一个测试'; //$a = 'xxxxbbbbbnnn'; $b = GBsubstr($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.0070.00718.43
8.3.50.0090.01222.11
8.3.40.0080.00818.97
8.3.30.0040.01118.67
8.3.20.0030.00618.76
8.3.10.0000.00820.92
8.3.00.0040.00423.70
8.2.180.0090.00618.31
8.2.170.0110.01122.96
8.2.160.0070.00720.57
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0070.00026.16
8.2.120.0070.00020.84
8.2.110.0090.00022.04
8.2.100.0110.00018.03
8.2.90.0000.00819.17
8.2.80.0040.00418.03
8.2.70.0060.00317.50
8.2.60.0090.00018.05
8.2.50.0080.00018.10
8.2.40.0040.00418.02
8.2.30.0000.00819.79
8.2.20.0080.00017.61
8.2.10.0080.00017.77
8.2.00.0000.00817.69
8.1.280.0090.00925.92
8.1.270.0050.00223.99
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0030.00623.84
8.1.230.0070.00417.76
8.1.220.0040.00417.79
8.1.210.0000.00818.77
8.1.200.0090.00017.35
8.1.190.0040.00417.10
8.1.180.0000.00818.10
8.1.170.0080.00018.59
8.1.160.0040.00418.91
8.1.150.0060.00318.55
8.1.140.0050.00317.38
8.1.130.0000.00717.87
8.1.120.0040.00417.42
8.1.110.0030.00517.42
8.1.100.0000.00717.31
8.1.90.0040.00417.41
8.1.80.0040.00417.41
8.1.70.0070.00017.41
8.1.60.0040.00417.65
8.1.50.0040.00417.55
8.1.40.0030.00617.54
8.1.30.0000.00717.65
8.1.20.0060.00317.66
8.1.10.0060.00317.48
8.1.00.0000.00817.50
8.0.300.0000.00718.77
8.0.290.0050.00316.75
8.0.280.0030.00318.40
8.0.270.0000.00717.17
8.0.260.0040.00416.86
8.0.250.0040.00417.09
8.0.240.0060.00317.02
8.0.230.0030.00317.02
8.0.220.0000.00716.94
8.0.210.0040.00416.90
8.0.200.0060.00016.93
8.0.190.0070.00016.96
8.0.180.0040.00416.92
8.0.170.0000.00716.86
8.0.160.0030.00317.06
8.0.150.0050.00316.92
8.0.140.0000.00816.85
8.0.130.0040.00413.41
8.0.120.0070.00016.77
8.0.110.0090.00017.02
8.0.100.0070.00016.81
8.0.90.0030.00517.06
8.0.80.0070.00716.98
8.0.70.0000.00816.95
8.0.60.0020.00517.04
8.0.50.0060.00316.82
8.0.30.0100.00917.15
8.0.20.0020.01717.40
8.0.10.0050.00216.91
8.0.00.0170.00116.86
7.4.330.0030.00314.72
7.4.320.0000.00616.54
7.4.300.0040.00416.61
7.4.290.0000.00716.63
7.4.280.0090.00016.65
7.4.270.0030.00316.55
7.4.260.0030.00313.20
7.4.250.0070.00016.60
7.4.240.0000.00816.54
7.4.230.0000.00716.65
7.4.220.0130.01016.60
7.4.210.0030.01016.59
7.4.200.0050.00216.44
7.4.190.0030.00316.79
7.4.160.0120.00316.64
7.4.150.0170.00017.40
7.4.140.0120.00717.86
7.4.130.0070.00916.53
7.4.120.0140.00716.50
7.4.110.0090.00816.68
7.4.100.0030.01316.56
7.4.90.0030.01316.68
7.4.80.0070.01019.37
7.4.70.0080.00816.66
7.4.60.0030.01416.71
7.4.50.0090.00016.62
7.4.40.0070.01122.27
7.4.30.0050.01116.30
7.4.00.0030.01414.91
7.3.330.0000.00513.41
7.3.320.0060.00013.33
7.3.310.0050.00316.29
7.3.300.0000.00716.27
7.3.290.0090.00616.39
7.3.280.0060.01016.41
7.3.270.0100.00717.40
7.3.260.0080.00918.24
7.3.250.0110.00716.53
7.3.240.0030.01316.73
7.3.230.0100.00716.39
7.3.210.0030.02016.58
7.3.200.0090.01019.39
7.3.190.0030.01216.75
7.3.180.0120.00316.65
7.3.170.0080.01116.67
7.3.160.0090.00616.62
7.3.120.0090.00814.81
7.3.110.0070.00714.70
7.3.100.0080.00414.86
7.3.90.0030.00715.00
7.3.80.0090.00615.13
7.3.70.0060.00314.80
7.3.60.0070.00714.74
7.3.50.0000.01115.02
7.3.40.0080.00514.81
7.3.30.0060.00914.63
7.3.20.0040.01116.75
7.3.10.0080.00316.48
7.3.00.0080.00316.64
7.2.330.0060.01216.60
7.2.320.0080.00816.64
7.2.310.0070.01016.66
7.2.300.0040.01616.73
7.2.290.0150.00416.87
7.2.250.0100.01015.21
7.2.240.0070.01415.29
7.2.230.0080.00815.07
7.2.220.0060.00615.02
7.2.210.0090.00615.20
7.2.200.0060.01015.09
7.2.190.0080.00415.02
7.2.180.0060.00614.94
7.2.170.0030.01014.80
7.2.00.0040.01119.30
7.1.330.0030.01015.75
7.1.320.0030.00715.67
7.1.310.0060.00315.61
7.1.300.0050.00516.00
7.1.290.0040.01115.77
7.1.280.0090.00615.44
7.1.270.0040.00815.75
7.1.260.0030.00615.89
7.1.100.0000.01018.31
7.1.70.0000.00817.16
7.1.60.0060.01819.40
7.1.50.0030.02216.92
7.1.00.0000.06722.36
7.0.200.0000.01016.57
7.0.140.0070.07022.18
7.0.70.0100.07721.71
7.0.60.0170.06721.55
7.0.50.0030.08722.18
7.0.40.0130.06720.13
7.0.30.0030.08020.19
7.0.20.0070.08020.05
7.0.10.0070.07320.04
7.0.00.0070.06019.95
5.6.280.0000.07321.07
5.6.220.0070.07720.60
5.6.210.0000.07720.56
5.6.200.0000.07321.09
5.6.190.0100.08021.12
5.6.180.0030.06020.97
5.6.170.0030.08321.03
5.6.160.0030.08321.09
5.6.150.0130.07720.96
5.6.140.0070.08021.04
5.6.130.0070.07721.17
5.6.120.0100.06721.08
5.6.110.0130.07720.89
5.6.100.0030.08320.94
5.6.90.0030.06021.05
5.6.80.0070.07720.52
5.6.70.0030.07720.39
5.6.60.0130.06720.43
5.6.50.0100.08020.44
5.6.40.0100.07020.47
5.6.30.0130.06720.50
5.6.20.0030.07720.38
5.6.10.0000.07320.41
5.6.00.0000.08020.37
5.5.360.0030.08320.34
5.5.350.0070.07720.29
5.5.340.0030.08020.84
5.5.330.0030.08320.77
5.5.320.0000.08020.89
5.5.310.0030.08720.92
5.5.300.0070.04320.90
5.5.290.0000.06720.74
5.5.280.0070.08020.91
5.5.270.0030.08720.86
5.5.260.0030.08720.75
5.5.250.0030.08320.66
5.5.240.0130.07020.15
5.5.230.0070.07720.30
5.5.220.0070.05320.21
5.5.210.0130.07020.16
5.5.200.0070.05320.31
5.5.190.0130.07020.14
5.5.180.0030.08720.29
5.5.160.0030.09020.29
5.5.150.0030.07720.29
5.5.140.0030.04020.16
5.5.130.0130.07020.24
5.5.120.0070.05320.27
5.5.110.0030.07720.28
5.5.100.0030.07020.11
5.5.90.0100.07320.07
5.5.80.0070.06320.14
5.5.70.0000.06720.07
5.5.60.0000.06320.12
5.5.50.0100.07719.97
5.5.40.0000.06720.10
5.5.30.0000.06320.06
5.5.20.0000.08020.09
5.5.10.0030.08020.14
5.5.00.0070.06020.04
5.4.450.0070.07019.28
5.4.440.0000.08019.20
5.4.430.0030.07719.37
5.4.420.0030.08019.44
5.4.410.0000.08319.14
5.4.400.0130.06319.13
5.4.390.0100.07318.88
5.4.380.0030.08319.10
5.4.370.0070.07318.88
5.4.360.0130.07019.04
5.4.350.0000.05719.04
5.4.340.0070.07718.95
5.4.320.0070.07319.04
5.4.310.0030.08019.02
5.4.300.0030.07319.15
5.4.290.0000.08319.20
5.4.280.0030.08019.09
5.4.270.0030.08019.09
5.4.260.0030.07719.05
5.4.250.0100.07019.13
5.4.240.0100.07019.23
5.4.230.0070.07018.86
5.4.220.0100.07718.84
5.4.210.0000.08019.03
5.4.200.0000.06319.04
5.4.190.0100.07019.04
5.4.180.0030.07019.13
5.4.170.0030.07719.20
5.4.160.0130.07019.12
5.4.150.0030.07319.12
5.4.140.0070.07016.34
5.4.130.0070.07016.17
5.4.120.0070.07016.18
5.4.110.0030.06316.50
5.4.100.0030.08016.41
5.4.90.0070.07016.56
5.4.80.0030.06316.45
5.4.70.0100.05716.36
5.4.60.0070.04716.46
5.4.50.0100.07016.24
5.4.40.0000.07716.52
5.4.30.0070.06716.38
5.4.20.0070.06716.44
5.4.10.0030.07316.32
5.4.00.0100.05015.80
5.3.290.0030.07714.81
5.3.280.0000.07714.66
5.3.270.0030.07014.70
5.3.260.0100.07014.70
5.3.250.0070.07014.67
5.3.240.0070.07314.58
5.3.230.0200.05714.63
5.3.220.0070.07014.63
5.3.210.0070.07014.66
5.3.200.0030.07714.52
5.3.190.0000.05714.67
5.3.180.0030.07314.69
5.3.170.0070.07014.63
5.3.160.0000.08014.68
5.3.150.0070.06014.55
5.3.140.0030.06314.57
5.3.130.0070.07314.63
5.3.120.0070.07714.61
5.3.110.0030.06014.67
5.3.100.0030.07314.02
5.3.90.0100.07013.95
5.3.80.0030.07314.01
5.3.70.0000.06314.03
5.3.60.0100.06714.01
5.3.50.0030.07314.02
5.3.40.0030.06313.98
5.3.30.0070.06313.90
5.3.20.0030.06013.83
5.3.10.0000.05313.59
5.3.00.0030.06013.63
5.2.170.0030.06311.22
5.2.160.0030.06011.29
5.2.150.0030.06011.08
5.2.140.0070.05711.14
5.2.130.0030.06311.23
5.2.120.0030.06311.23
5.2.110.0030.06011.00
5.2.100.0000.06011.12
5.2.90.0070.02711.02
5.2.80.0030.03011.10
5.2.70.0000.04010.96
5.2.60.0000.03311.15
5.2.50.0000.03011.06
5.2.40.0000.03010.93
5.2.30.0030.02710.96
5.2.20.0030.02710.92
5.2.10.0030.02710.77
5.2.00.0030.02310.83
5.1.60.0000.02010.08
5.1.50.0030.02310.11
5.1.40.0000.02310.07
5.1.30.0030.02010.43
5.1.20.0000.02310.35
5.1.10.0000.0239.91
5.1.00.0000.02010.20
5.0.50.0000.0178.68
5.0.40.0000.0178.63
5.0.30.0000.0338.63
5.0.20.0000.0178.63
5.0.10.0000.0178.63
5.0.00.0000.0238.63
4.4.90.0000.0178.63
4.4.80.0030.0138.63
4.4.70.0000.0178.63
4.4.60.0000.0178.63
4.4.50.0030.0138.63
4.4.40.0000.0238.63
4.4.30.0000.0138.63
4.4.20.0000.0178.63
4.4.10.0000.0138.63
4.4.00.0000.0238.63
4.3.110.0030.0108.63
4.3.100.0030.0108.63
4.3.90.0030.0108.63
4.3.80.0000.0208.63
4.3.70.0000.0138.63
4.3.60.0000.0138.63
4.3.50.0000.0138.63
4.3.40.0000.0238.63
4.3.30.0000.0178.63
4.3.20.0000.0178.63
4.3.10.0000.0178.63
4.3.00.0000.0138.63

preferences:
40.69 ms | 401 KiB | 5 Q