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.0090.00618.55
8.3.50.0120.00721.96
8.3.40.0120.00318.59
8.3.30.0070.00718.92
8.3.20.0040.00420.04
8.3.10.0050.00321.93
8.3.00.0080.00022.21
8.2.180.0110.00418.29
8.2.170.0030.01222.96
8.2.160.0150.00620.81
8.2.150.0040.00424.18
8.2.140.0030.00624.66
8.2.130.0000.00726.16
8.2.120.0050.00319.36
8.2.110.0070.00322.16
8.2.100.0120.00017.72
8.2.90.0000.00919.08
8.2.80.0040.00417.97
8.2.70.0030.00517.38
8.2.60.0050.00318.04
8.2.50.0080.00018.07
8.2.40.0000.00817.96
8.2.30.0040.00418.07
8.2.20.0040.00417.52
8.2.10.0050.00317.75
8.2.00.0080.00017.69
8.1.280.0070.01125.92
8.1.270.0040.00424.66
8.1.260.0080.00026.35
8.1.250.0130.00728.09
8.1.240.0060.00323.79
8.1.230.0070.00319.01
8.1.220.0030.00517.74
8.1.210.0000.00918.77
8.1.200.0060.00317.25
8.1.190.0040.00417.52
8.1.180.0030.00618.10
8.1.170.0000.00818.49
8.1.160.0030.00521.97
8.1.150.0040.00418.70
8.1.140.0030.00617.44
8.1.130.0070.00017.84
8.1.120.0070.00017.46
8.1.110.0000.00717.51
8.1.100.0030.00317.35
8.1.90.0050.00217.36
8.1.80.0050.00217.37
8.1.70.0050.00217.34
8.1.60.0060.00317.54
8.1.50.0040.00417.54
8.1.40.0000.00717.44
8.1.30.0060.00317.71
8.1.20.0030.00517.56
8.1.10.0050.00217.47
8.1.00.0030.00517.43
8.0.300.0040.00418.77
8.0.290.0030.00317.18
8.0.280.0000.00718.50
8.0.270.0000.00817.27
8.0.260.0030.00316.92
8.0.250.0000.00717.06
8.0.240.0030.00317.06
8.0.230.0000.00717.00
8.0.220.0000.00716.96
8.0.210.0000.00716.94
8.0.200.0000.00717.11
8.0.190.0030.00317.09
8.0.180.0030.00517.09
8.0.170.0000.00816.94
8.0.160.0070.00016.89
8.0.150.0040.00416.98
8.0.140.0000.00716.87
8.0.130.0030.00313.46
8.0.120.0050.00316.96
8.0.110.0040.00416.92
8.0.100.0050.00216.97
8.0.90.0040.00416.90
8.0.80.0040.01117.02
8.0.70.0040.00416.90
8.0.60.0000.00716.93
8.0.50.0000.00717.04
8.0.30.0080.01217.08
8.0.20.0070.01317.40
8.0.10.0040.00416.91
8.0.00.0080.01316.73
7.4.330.0000.00715.14
7.4.320.0000.00616.60
7.4.300.0060.00016.61
7.4.290.0030.00316.65
7.4.280.0030.00316.63
7.4.270.0100.00016.42
7.4.260.0040.00416.61
7.4.250.0040.00416.46
7.4.240.0040.00416.48
7.4.230.0000.00716.62
7.4.220.0060.01216.38
7.4.210.0060.00916.60
7.4.200.0070.00016.62
7.4.190.0040.00416.68
7.4.160.0060.01316.29
7.4.150.0110.00717.40
7.4.140.0060.01217.86
7.4.130.0130.00416.47
7.4.120.0150.00516.57
7.4.110.0100.00716.48
7.4.100.0070.01116.50
7.4.90.0110.00616.67
7.4.80.0090.00916.46
7.4.70.0090.00916.60
7.4.60.0070.01016.46
7.4.50.0030.00616.56
7.4.40.0040.00722.77
7.4.30.0070.01416.46
7.4.00.0040.01114.95
7.3.330.0000.00513.16
7.3.320.0030.00313.27
7.3.310.0050.00216.30
7.3.300.0000.00716.22
7.3.290.0190.00016.38
7.3.280.0050.01316.34
7.3.270.0130.00617.40
7.3.260.0210.00316.31
7.3.250.0120.00616.33
7.3.240.0100.00916.30
7.3.230.0130.00316.39
7.3.210.0070.01016.48
7.3.200.0000.01919.39
7.3.190.0110.00716.32
7.3.180.0070.01116.32
7.3.170.0090.00616.59
7.3.160.0100.00716.42
7.3.120.0060.01214.88
7.3.110.0120.00514.69
7.3.100.0020.01414.54
7.3.90.0060.00914.90
7.3.80.0050.00914.96
7.3.70.0060.01214.69
7.3.60.0060.00914.80
7.3.50.0120.00414.82
7.3.40.0060.00714.73
7.3.30.0080.00514.67
7.3.20.0060.00616.68
7.3.10.0090.00316.72
7.3.00.0030.00816.54
7.2.330.0060.01116.58
7.2.320.0130.01016.73
7.2.310.0110.00516.37
7.2.300.0140.00316.63
7.2.290.0100.00616.42
7.2.250.0060.01115.10
7.2.240.0050.01414.85
7.2.230.0080.00814.61
7.2.220.0110.00315.00
7.2.210.0070.00815.06
7.2.200.0030.00714.97
7.2.190.0050.01314.89
7.2.180.0050.01014.82
7.2.170.0050.00914.93
7.2.60.0060.00916.79
7.2.00.0060.00619.42
7.1.330.0040.01115.75
7.1.320.0050.00715.78
7.1.310.0030.01416.04
7.1.300.0040.00915.85
7.1.290.0060.00615.82
7.1.280.0060.00615.78
7.1.270.0080.00715.77
7.1.260.0050.00615.86
7.1.200.0040.00415.64
7.1.100.0000.01518.19
7.1.70.0000.00716.94
7.1.60.0130.01019.82
7.1.50.0100.01016.87
7.1.00.0030.07322.36
7.0.200.0080.00416.91
7.0.140.0100.06722.12
7.0.80.0170.07319.94
7.0.70.0100.07019.86
7.0.60.0030.08319.97
7.0.50.0070.08320.40
7.0.40.0030.08320.03
7.0.30.0100.07719.95
7.0.20.0070.05720.19
7.0.10.0070.07720.07
7.0.00.0100.07020.18
5.6.280.0070.06721.10
5.6.230.0030.08320.63
5.6.220.0130.07020.68
5.6.210.0170.07020.62
5.6.200.0130.07021.11
5.6.190.0070.07321.08
5.6.180.0000.07321.11
5.6.170.0070.09021.06
5.6.160.0100.04321.01
5.6.150.0070.06020.96
5.6.140.0170.07021.02
5.6.130.0170.05320.93
5.6.120.0100.08021.03
5.6.110.0100.04721.01
5.6.100.0130.08021.13
5.6.90.0100.06721.04
5.6.80.0070.07320.52
5.6.70.0100.04020.32
5.6.60.0000.08320.41
5.6.50.0100.07720.45
5.6.40.0070.07720.43
5.6.30.0170.06320.54
5.6.20.0070.04720.39
5.6.10.0030.05020.41
5.6.00.0070.08320.37
5.5.370.0030.08320.46
5.5.360.0100.08020.34
5.5.350.0070.07320.35
5.5.340.0100.07320.84
5.5.330.0100.07320.79
5.5.320.0000.08320.79
5.5.310.0100.06720.77
5.5.300.0100.04320.80
5.5.290.0100.07320.92
5.5.280.0070.08020.64
5.5.270.0070.08720.83
5.5.260.0100.08020.88
5.5.250.0030.05020.55
5.5.240.0030.06720.30
5.5.230.0130.04020.27
5.5.220.0100.07320.15
5.5.210.0070.07720.16
5.5.200.0070.07720.14
5.5.190.0230.06320.25
5.5.180.0130.05720.29
5.5.160.0030.08020.18
5.5.150.0000.07720.15
5.5.140.0030.04720.11
5.5.130.0070.07720.14
5.5.120.0130.07320.12
5.5.110.0130.06020.11
5.5.100.0130.07020.12
5.5.90.0030.07320.10
5.5.80.0200.06020.06
5.5.70.0070.07719.93
5.5.60.0000.08720.05
5.5.50.0000.06020.14
5.5.40.0070.07320.15
5.5.30.0000.08320.15
5.5.20.0070.06720.14
5.5.10.0170.06720.08
5.5.00.0000.05720.14
5.4.450.0130.06319.37
5.4.440.0170.07319.37
5.4.430.0170.05319.41
5.4.420.0130.05719.27
5.4.410.0070.04719.38
5.4.400.0100.06318.88
5.4.390.0170.07019.23
5.4.380.0100.07319.13
5.4.370.0130.07019.21
5.4.360.0130.07319.14
5.4.350.0200.06318.88
5.4.340.0170.07319.04
5.4.320.0030.05719.03
5.4.310.0100.07018.85
5.4.300.0000.08019.12
5.4.290.0100.06319.17
5.4.280.0070.08019.06
5.4.270.0100.07018.87
5.4.260.0170.06319.03
5.4.250.0070.05319.17
5.4.240.0070.07719.18
5.4.230.0030.07318.87
5.4.220.0070.07319.00
5.4.210.0000.05019.08
5.4.200.0030.08019.17
5.4.190.0100.08019.17
5.4.180.0130.03719.22
5.4.170.0100.07019.11
5.4.160.0100.07319.19
5.4.150.0070.07719.07
5.4.140.0070.07716.45
5.4.130.0000.07716.39
5.4.120.0100.07316.31
5.4.110.0100.07016.32
5.4.100.0030.05016.40
5.4.90.0130.06716.50
5.4.80.0170.03716.25
5.4.70.0070.04016.50
5.4.60.0100.07016.48
5.4.50.0000.05016.25
5.4.40.0070.04316.42
5.4.30.0070.04716.47
5.4.20.0070.07716.42
5.4.10.0000.08316.40
5.4.00.0070.07315.88
5.3.290.0200.06314.73
5.3.280.0000.08314.51
5.3.270.0130.07014.72
5.3.260.0030.04014.63
5.3.250.0070.06714.63
5.3.240.0070.07314.58
5.3.230.0070.08014.53
5.3.220.0100.04714.66
5.3.210.0030.04314.53
5.3.200.0000.08314.63
5.3.190.0200.05714.52
5.3.180.0030.07014.65
5.3.170.0070.07714.57
5.3.160.0030.07714.52
5.3.150.0100.07014.61
5.3.140.0030.07314.61
5.3.130.0070.07014.50
5.3.120.0030.05714.54
5.3.110.0030.07714.61
5.3.100.0030.07314.03
5.3.90.0100.06714.13
5.3.80.0070.07314.08
5.3.70.0030.05714.11
5.3.60.0100.07014.06
5.3.50.0070.07313.97
5.3.40.0070.07314.02
5.3.30.0100.07013.96
5.3.20.0030.07313.74
5.3.10.0000.06013.54
5.3.00.0030.07713.78
5.2.170.0070.05711.73
5.2.160.0100.05711.73
5.2.150.0030.05311.73
5.2.140.0030.06311.73
5.2.130.0030.05311.73
5.2.120.0030.06011.73
5.2.110.0030.06311.73
5.2.100.0070.05311.73
5.2.90.0070.05711.73
5.2.80.0100.03711.73
5.2.70.0070.05711.73
5.2.60.0030.06011.73
5.2.50.0030.05311.73
5.2.40.0030.06311.73
5.2.30.0070.06311.73
5.2.20.0030.04711.73
5.2.10.0070.06011.73
5.2.00.0000.04311.73
5.1.60.0030.05011.73
5.1.50.0070.04311.73
5.1.40.0170.02011.73
5.1.30.0100.05011.73
5.1.20.0000.06011.73
5.1.10.0030.03311.73
5.1.00.0000.06011.73
5.0.50.0030.03311.73
5.0.40.0070.04011.73
5.0.30.0030.06311.73
5.0.20.0070.02711.73
5.0.10.0030.03711.73
5.0.00.0000.06011.73
4.4.90.0030.03011.73
4.4.80.0000.03711.73
4.4.70.0000.02711.73
4.4.60.0000.03711.73
4.4.50.0030.03011.73
4.4.40.0030.04311.73
4.4.30.0030.02011.73
4.4.20.0000.02011.73
4.4.10.0100.02711.73
4.4.00.0000.04011.73
4.3.110.0030.02711.73
4.3.100.0000.02711.73
4.3.90.0070.03011.73
4.3.80.0070.04011.73
4.3.70.0030.03011.73
4.3.60.0000.03011.73
4.3.50.0000.03711.73
4.3.40.0000.04011.73
4.3.30.0000.03311.73
4.3.20.0000.02711.73
4.3.10.0030.03011.73
4.3.00.0000.03311.73

preferences:
45.39 ms | 401 KiB | 5 Q