3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Clown Emoji // "🤡".length = 2 in Javascript (Firefox) // '🤡abc'.length = 5 in Javascript (Firefox) // . = Byte, () = Surrogate pairs $x = '🤡'; // 4 bytes (UTF-8 (....)) $y = '🤡abc'; // 4 + 3 = 7 bytes (UTF-8 (....) . . .) // In PHP, strings are simply raw byte streams. Right now $x and $y are stored as UTF-8 because // I copy pasted them from my browser. echo "--- These are UTF-8 ---"."\n"; echo "\$x Bytes: ".strlen($x)."\n"; echo "\$x Unicode Codepoint Count (\"characters\"): ".mb_strlen($x, "UTF-8")."\n"; echo "\$x Hex Representation: ".bin2hex($x)."\n"; echo "\$y Bytes: ".strlen($y)."\n"; echo "\$y Unicode Codepoint Count (\"characters\"): ".mb_strlen($y, "UTF-8")."\n"; echo "\$y Hex Representation: ".bin2hex($y)."\n"; echo "--- End ---"."\n"; // Now, lets convert them to UTF-16 where each codepoint is 2 bytes and a surrogate pair is 4 bytes $x1 = mb_convert_encoding($x, "UTF-16", "UTF-8"); // Still 4 bytes! (UTF-16 (.. ..)) $y1 = mb_convert_encoding($y, "UTF-16", "UTF-8"); // 4 + 6 = 10 bytes (UTF-16 (.. ..) .. .. ..) echo "--- These are UTF-16 ---"."\n"; echo "\$x1 Bytes: ".strlen($x1)."\n"; echo "\$x1 Unicode Codepoint Count (\"characters\"): ".mb_strlen($x1, "UTF-16")."\n"; echo "\$x1 Hex Representation: ".bin2hex($x1)."\n"; echo "\$y1 Bytes: ".strlen($y1)."\n"; echo "\$y1 Unicode Codepoint Count (\"characters\"): ".mb_strlen($y1, "UTF-16")."\n"; echo "\$y1 Hex Representation: ".bin2hex($y1)."\n"; echo "--- End ---"."\n"; // Now, Javascript's String is sort of like PHP's raw string byte stream, except: // >>>>>> // JavaScript treats code units as individual characters, while humans generally think in terms of Unicode characters. // This has some unfortunate consequences for Unicode characters outside the BMP. Since surrogate pairs consist of // two code units, '𝌆'.length == 2, even though there’s only one Unicode character there. The individual surrogate // halves are being exposed as if they were characters: '𝌆' == '\uD834\uDF06'. // <<<<<< https://mathiasbynens.be/notes/javascript-encoding // What this basically means is that while proper counting of UTF-16 codepoints would count surrogate pairs (.. ..) as // length 1, Javascript counts them separately as .. .. = length 2. // So, our characters $x1 and $y1 are counted in Javascript as: // $x1 | .. .. = 2 // $y1 | .. .. .. .. .. = 5 // Now it looks obvious that, to emulate Javascript's behaviour we simply need to count the number of bytes // in the UTF-16 encoding, and divide that by half. echo "--- These are UTF-16 ---"."\n"; echo "\$x1 Javascript Emulated strlen/2: ".(strlen($x1)/2)."\n"; echo "\$y1 Javascript Emulated strlen/2: ".(strlen($y1)/2)."\n"; echo "--- End ---"."\n"; // And we can see that Javascript's length behaviour is emulated.

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.4.130.0170.00718.56
8.4.120.0150.00624.03
8.4.110.0100.00920.70
8.4.100.0140.00618.74
8.4.90.0110.00920.49
8.4.80.0050.00318.65
8.4.70.0030.00619.00
8.4.60.0130.00718.86
8.4.50.0060.01420.46
8.4.40.0090.01019.46
8.4.30.0110.00717.62
8.4.20.0140.00317.60
8.4.10.0030.00619.34
8.3.260.0060.00416.45
8.3.250.0130.00718.80
8.3.240.0110.00917.06
8.3.230.0120.00716.77
8.3.220.0110.00718.94
8.3.210.0110.00516.50
8.3.200.0100.00816.72
8.3.190.0110.00817.29
8.3.180.0060.00418.74
8.3.170.0090.00616.48
8.3.160.0110.00716.96
8.3.150.0110.00716.57
8.3.140.0040.00419.21
8.3.130.0050.00318.42
8.3.120.0160.00319.07
8.3.110.0050.00516.60
8.3.100.0090.00024.06
8.3.90.0110.00426.77
8.3.80.0040.00418.43
8.3.70.0110.00818.30
8.3.60.0130.00316.38
8.3.50.0090.01022.77
8.3.40.0060.00918.79
8.3.30.0070.00718.59
8.3.20.0050.00321.86
8.3.10.0070.00022.09
8.3.00.0030.00619.26
8.2.290.0100.00920.19
8.2.280.0120.00718.52
8.2.270.0140.00416.57
8.2.260.0150.00416.66
8.2.250.0060.00316.55
8.2.240.0100.00018.73
8.2.230.0080.00020.94
8.2.220.0060.00637.54
8.2.210.0080.00026.77
8.2.200.0060.00316.50
8.2.190.0090.00616.63
8.2.180.0120.00918.01
8.2.170.0110.00322.96
8.2.160.0070.00720.38
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0050.00317.91
8.2.120.0080.00026.35
8.2.110.0060.00322.25
8.2.100.0080.00418.10
8.2.90.0080.00019.89
8.2.80.0040.00418.04
8.2.70.0050.00317.79
8.2.60.0070.00018.09
8.2.50.0000.00918.10
8.2.40.0040.00420.45
8.2.30.0000.00821.03
8.2.20.0020.00518.08
8.2.10.0000.00718.30
8.2.00.0040.00417.83
8.1.330.0090.01121.79
8.1.320.0100.00917.81
8.1.310.0100.00616.20
8.1.300.0040.01120.14
8.1.290.0110.00030.84
8.1.280.0110.00425.92
8.1.270.0040.00423.79
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0110.01122.06
8.1.230.0070.00420.88
8.1.220.0060.00317.74
8.1.210.0000.00918.77
8.1.200.0030.00617.35
8.1.190.0030.00517.66
8.1.180.0040.00418.10
8.1.170.0030.00618.78
8.1.160.0000.00818.99
8.1.150.0000.00720.31
8.1.140.0000.00719.68
8.1.130.0000.00817.47
8.1.120.0040.00417.46
8.1.110.0040.00417.55
8.1.100.0000.00817.44
8.1.90.0040.00417.50
8.1.80.0040.00417.52
8.1.70.0070.00017.47
8.1.60.0040.00417.64
8.1.50.0030.00717.64
8.1.40.0000.00717.52
8.1.30.0000.00817.66
8.1.20.0000.00817.74
8.1.10.0040.00417.54
8.1.00.0030.00517.43
8.0.300.0000.00719.73
8.0.290.0040.00416.75
8.0.280.0000.00818.45
8.0.270.0000.00817.43
8.0.260.0000.00716.86
8.0.250.0030.00317.02
8.0.240.0050.00416.98
8.0.230.0050.00317.03
8.0.220.0000.00716.98
8.0.210.0020.00516.95
8.0.200.0030.00317.07
8.0.190.0050.00316.94
8.0.180.0050.00317.01
8.0.170.0000.00717.04
8.0.160.0030.00616.90
8.0.150.0040.00416.92
8.0.140.0050.00216.93
8.0.130.0000.00513.48
8.0.120.0040.00417.00
8.0.110.0000.00716.81
8.0.100.0040.00416.82
8.0.90.0000.00817.06
8.0.80.0030.01316.92
8.0.70.0030.00516.93
8.0.60.0000.00717.05
8.0.50.0040.00416.86
8.0.30.0100.00916.98
8.0.20.0100.01117.33
8.0.10.0060.00916.98
8.0.00.0100.01016.92
7.4.330.0060.00315.71
7.4.320.0030.00316.63
7.4.300.0030.00316.55
7.4.290.0030.00316.64
7.4.280.0040.00416.63
7.4.270.0040.00416.52
7.4.260.0040.00416.52
7.4.250.0000.00716.55
7.4.240.0070.00016.56
7.4.230.0070.00016.66
7.4.220.0070.01016.42
7.4.210.0070.01316.55
7.4.200.0070.00016.72
7.4.160.0090.00916.57
7.4.150.0080.00916.91
7.4.140.0110.00717.54
7.4.130.0120.00616.56
7.4.120.0100.00916.51
7.4.110.0090.00816.59
7.4.100.0040.01416.64
7.4.90.0170.00316.44
7.4.80.0090.01117.95
7.4.70.0100.00916.39
7.4.60.0090.00716.54
7.4.50.0080.01116.40
7.4.40.0190.01016.57
7.4.30.0130.00616.54
7.4.20.0030.01216.58
7.4.10.0040.01116.53
7.4.00.0050.01215.79
7.3.330.0060.00013.24
7.3.320.0030.00313.27
7.3.310.0040.00416.22
7.3.300.0020.00516.34
7.3.290.0070.00716.32
7.3.280.0110.00716.33
7.3.270.0050.01116.85
7.3.260.0100.00716.48
7.3.250.0100.00916.44
7.3.240.0110.00816.45
7.3.230.0050.01116.32
7.3.220.0040.01516.34
7.3.210.0090.01116.33
7.3.200.0090.00916.32
7.3.190.0100.00816.24
7.3.180.0060.01216.49
7.3.170.0070.01216.45
7.3.160.0080.01016.29
7.3.150.0040.01816.18
7.3.140.0030.01516.31
7.3.130.0060.01216.29
7.3.120.0100.00316.26
7.3.110.0000.01416.14
7.3.100.0130.00316.23
7.3.90.0080.01116.57
7.3.80.0060.01116.32
7.3.70.0090.00916.36
7.3.60.0060.00916.35
7.3.50.0100.01016.41
7.3.40.0060.00816.46
7.3.30.0120.00816.43
7.3.20.0030.01316.45
7.3.10.0060.00916.34
7.3.00.0150.00316.33
7.2.340.0160.01616.44
7.2.330.0160.00916.59
7.2.320.0160.01116.68
7.2.310.0130.01416.62
7.2.300.0150.00916.64
7.2.290.0190.00616.67
7.2.280.0230.01016.54
7.2.270.0290.00316.48
7.2.260.0210.00716.53
7.2.250.0160.01316.47
7.2.240.0190.01016.51
7.2.230.0170.01716.44
7.2.220.0230.00316.43
7.2.210.0300.01016.54
7.2.200.0210.00916.61
7.2.190.0170.01316.61
7.2.180.0320.01416.57
7.2.170.0190.01216.69
7.2.160.0160.01916.71
7.2.150.0170.01416.75
7.2.140.0240.01016.71
7.2.130.0190.00916.87
7.2.120.0180.01416.93
7.2.110.0370.00416.82
7.2.100.0350.00916.74
7.2.90.0190.01216.71
7.2.80.0260.00616.67
7.2.70.0250.00916.81
7.2.60.0080.01416.84
7.2.50.0180.00716.80
7.2.40.0220.00616.80
7.2.30.0200.00816.73
7.2.20.0260.01016.91
7.2.10.0590.01016.73
7.2.00.0170.01116.82
7.1.330.0140.01115.60
7.1.320.0140.00915.59
7.1.310.0160.01315.57
7.1.300.0170.00815.52
7.1.290.0180.00915.48
7.1.280.0160.01215.56
7.1.270.0200.00515.56
7.1.260.0150.01215.42
7.1.250.0220.00615.40
7.1.240.0240.00415.39
7.1.230.0290.00515.55
7.1.220.0180.01115.53
7.1.210.0190.01115.38
7.1.200.0230.00215.35
7.1.190.0200.01115.47
7.1.180.0170.01015.46
7.1.170.0250.00415.51
7.1.160.0210.00715.48
7.1.150.0180.00915.41
7.1.140.0200.00815.46
7.1.130.0080.01615.46
7.1.120.0150.00915.39
7.1.110.0100.01515.52
7.1.100.0190.00815.59
7.1.90.0140.00915.45
7.1.80.0320.00615.61
7.1.70.0090.00816.17
7.1.60.0100.01016.38
7.1.50.0140.00915.59
7.1.40.0110.02515.57
7.1.30.0280.00015.56
7.1.20.0410.03831.46
7.1.10.0110.03318.90
7.1.00.0120.03418.85
7.0.330.0190.00815.21
7.0.320.0170.00915.30
7.0.310.0090.01715.22
7.0.300.0150.00815.10
7.0.290.0240.00715.37
7.0.280.0180.00815.20
7.0.270.0180.00715.24
7.0.260.0080.01415.15
7.0.250.0130.01315.32
7.0.240.0130.01015.33
7.0.230.0130.01015.30
7.0.220.0180.00515.29
7.0.210.0230.00415.38
7.0.200.0130.00716.08
7.0.190.0120.01215.32
7.0.180.0180.00415.18
7.0.170.0140.00815.36
7.0.160.0070.04318.50
7.0.150.0090.03618.50
7.0.140.0130.03218.54
7.0.130.0130.03218.66
7.0.120.0120.03818.71
7.0.110.0120.03818.58
7.0.100.0160.03718.60
7.0.90.0160.03318.50
7.0.80.0140.03018.52
7.0.70.0210.03418.48
7.0.60.0130.03418.50
7.0.50.0180.02918.47
7.0.40.0230.03418.58
7.0.30.0180.03418.53
7.0.20.0130.03318.45
7.0.10.0170.02818.46
7.0.00.0100.03718.54
5.6.400.0170.01115.79
5.6.390.0180.00615.83
5.6.380.0190.00915.86
5.6.370.0220.01115.89
5.6.360.0160.01015.78
5.6.350.0160.01115.85
5.6.340.0130.01315.78
5.6.330.0200.00615.75
5.6.320.0220.00615.85
5.6.310.0190.00615.73
5.6.300.0180.00615.73
5.6.290.0080.01515.88
5.6.280.0130.01015.82
5.6.270.0160.00815.86
5.6.260.0210.00715.77
5.6.250.0240.00315.93
5.6.240.0170.01415.79
5.6.230.0190.00416.07
5.6.220.0150.01115.84
5.6.210.0260.00915.82
5.6.200.0210.01016.06
5.6.190.0170.01415.89
5.6.180.0180.00916.02
5.6.170.0180.01216.00
5.6.160.0190.01215.89
5.6.150.0200.01616.03
5.6.140.0140.01416.06
5.6.130.0210.00715.84
5.6.120.0150.01516.06
5.6.110.0190.01415.91
5.6.100.0180.00715.80
5.6.90.0200.00915.70
5.6.80.0190.00615.74
5.6.70.0200.01015.98
5.6.60.0260.00716.01
5.6.50.0180.00715.79
5.6.40.0160.00815.79
5.6.30.0160.01615.91
5.6.20.0160.00715.81
5.6.10.0100.01715.81
5.6.00.0100.01315.80

preferences:
28.62 ms | 403 KiB | 5 Q