3v4l.org

run code in 300+ PHP versions simultaneously
<?php function string_shift_left($input, $inputlen, $bits, &$output = null) { $skip = (int) ($bits / 8); $copylen = (int) ($inputlen - $skip); $offset = ($bits % 8) & 0xff; $mask = ~(0xff >> $offset) & 0xff; $output = str_pad('', $inputlen + 1, "\x00"); echo "$skip $copylen $offset $mask\n"; if ($offset == 0) { /* Shifting multiples of 8 allows us to simply copy the relevant bytes */ for ($i = 0; $i < $copylen; $i++) { $output[$i] = $input[$i + $skip]; } return; } for ($i = 0; $i < $copylen; $i++) { $left = (ord($input[$i + $skip]) << $offset) & 0xff; $right = (ord($input[$i + $skip + 1]) & $mask) >> (8 - $offset); printf("%08b %08b\n", $left, $right); $output[$i] = chr(($left | $right) & 0xff); } } function string_shift_right($input, $inputlen, $bits, &$output = null) { $skip = (int) ($bits / 8); $copylen = (int) ($inputlen - $skip); $offsetr = ($bits % 8) & 0xff; $signbits = (ord($input[0]) & 0x80) == 0 ? 0 : 255; echo "$skip $copylen $offsetr $signbits\n"; $output = str_pad('', $inputlen + 1, "\x00"); for ($i = 0; $i < $skip; $i++) { $output[$i] = chr($signbits); } if ($offsetr == 0) { /* Shifting multiples of 8 allows us to simply copy the relevant bytes */ for ($i = $skip, $l = $i + $copylen; $i < $l; $i++) { $output[$i] = $input[$i - $skip]; } return; } $offsetl = 8 - $offsetr; $mask = ~(0xff >> $offsetr) & 0xff; $output[$skip] = chr(($signbits & ~(0xff >> $offsetl)) | (ord($input[0]) >> $offsetl)); for ($i = $skip + 1, $l = $skip + $copylen; $i < $l; $i++) { $left = ((ord($input[$i - $skip]) & $mask) >> $offsetr); $right = (ord($input[($i - $skip) + 1]) << $offsetl); printf("%08b %08b\n", $left, $right); $output[$i] = chr($left | $right); } /* for ($i = 0; $i < $copylen; $i++) { $left = (ord($input[$i + $skip]) << $offset) & 0xff; $right = (ord($input[$i + $skip + 1]) & $mask) >> (8 - $offset); printf("%08b %08b\n", $left, $right); $output[$i] = chr(($left | $right) & 0xff); } */ } $input = "abc\x00"; $bits = 4; string_shift_right($input, strlen($input) - 1, $bits, $output); for ($i = 0; $i < strlen($input); $i++) { printf("\n%02x: %08b", ord($input[$i]), ord($input[$i])); } for ($i = 0; $i < strlen($output); $i++) { printf("\n%02x: %08b", ord($output[$i]), ord($output[$i])); }

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.0040.01118.43
8.3.50.0110.01321.88
8.3.40.0120.00918.73
8.3.30.0110.00419.17
8.3.20.0040.00420.34
8.3.10.0000.00922.04
8.3.00.0000.00822.34
8.2.180.0120.00918.32
8.2.170.0150.00422.96
8.2.160.0100.00319.16
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0050.00326.16
8.2.120.0090.00019.36
8.2.110.0060.00321.97
8.2.100.0040.00717.91
8.2.90.0060.00319.30
8.2.80.0080.00017.97
8.2.70.0030.00617.61
8.2.60.0080.00018.05
8.2.50.0040.00418.10
8.2.40.0050.00320.47
8.2.30.0040.00718.16
8.2.20.0000.00717.70
8.2.10.0040.00419.44
8.2.00.0040.00417.77
8.1.280.0100.01025.92
8.1.270.0080.00022.10
8.1.260.0030.01026.35
8.1.250.0040.00428.09
8.1.240.0090.00022.53
8.1.230.0040.00817.65
8.1.220.0000.00817.78
8.1.210.0000.00918.77
8.1.200.0070.00317.35
8.1.190.0050.00317.35
8.1.180.0040.00418.10
8.1.170.0060.00318.62
8.1.160.0000.00822.09
8.1.150.0070.00018.75
8.1.140.0040.00417.40
8.1.130.0040.00417.79
8.1.120.0000.00717.46
8.1.110.0050.00217.53
8.1.100.0000.00717.50
8.1.90.0040.00417.45
8.1.80.0040.00417.40
8.1.70.0030.00317.45
8.1.60.0050.00317.46
8.1.50.0000.00817.47
8.1.40.0040.00417.55
8.1.30.0030.00617.71
8.1.20.0000.00917.70
8.1.10.0070.00017.63
8.1.00.0000.00817.52
8.0.300.0040.00419.82
8.0.290.0040.00416.63
8.0.280.0070.00018.42
8.0.270.0000.00717.30
8.0.260.0030.00316.75
8.0.250.0040.00416.99
8.0.240.0040.00417.00
8.0.230.0070.00016.88
8.0.220.0000.00716.82
8.0.210.0090.00016.79
8.0.200.0000.00617.02
8.0.190.0030.00517.01
8.0.180.0030.00516.84
8.0.170.0000.00816.86
8.0.160.0080.00016.91
8.0.150.0080.00016.94
8.0.140.0030.00516.79
8.0.130.0030.00313.35
8.0.120.0050.00316.84
8.0.110.0030.00516.84
8.0.100.0000.00716.92
8.0.90.0070.00016.80
8.0.80.0100.01016.88
8.0.70.0030.00517.05
8.0.60.0000.00716.88
8.0.50.0030.00516.71
8.0.30.0090.00917.14
8.0.20.0140.00917.40
8.0.10.0030.00717.14
8.0.00.0130.00516.62
7.4.330.0060.00015.00
7.4.320.0000.00716.63
7.4.300.0000.00716.68
7.4.290.0040.00416.58
7.4.280.0000.00716.67
7.4.270.0040.00416.54
7.4.260.0040.00416.54
7.4.250.0030.00516.58
7.4.240.0040.00316.47
7.4.230.0030.00316.57
7.4.220.0120.00616.60
7.4.210.0080.00916.59
7.4.200.0030.00516.56
7.4.190.0080.00016.49
7.4.160.0120.00416.56
7.4.150.0110.00717.40
7.4.140.0140.00717.86
7.4.130.0090.00916.47
7.4.120.0100.00816.46
7.4.110.0100.01316.69
7.4.100.0140.00316.51
7.4.90.0060.01016.63
7.4.80.0060.01819.39
7.4.70.0030.01316.57
7.4.60.0110.00516.45
7.4.50.0040.00416.39
7.4.40.0060.00622.77
7.4.30.0120.00616.37
7.4.00.0030.01314.93
7.3.330.0030.00313.23
7.3.320.0000.00513.36
7.3.310.0030.00416.44
7.3.300.0000.00716.45
7.3.290.0000.01416.53
7.3.280.0090.00616.39
7.3.270.0090.00917.40
7.3.260.0030.01416.32
7.3.250.0080.00916.38
7.3.240.0110.01416.64
7.3.230.0110.00716.56
7.3.210.0110.00816.60
7.3.200.0100.01319.39
7.3.190.0060.01516.46
7.3.180.0030.01616.68
7.3.170.0050.01116.71
7.3.160.0100.00716.34
7.3.120.0100.00715.04
7.3.10.0030.00916.73
7.3.00.0000.01316.88
7.2.330.0150.00316.66
7.2.320.0030.01516.61
7.2.310.0140.00917.00
7.2.300.0060.01016.73
7.2.290.0090.00916.84
7.2.130.0090.00917.11
7.2.120.0070.00416.80
7.2.110.0040.01417.04
7.2.100.0070.00317.07
7.2.90.0110.00716.93
7.2.80.0090.00617.10
7.2.70.0040.00716.67
7.2.60.0130.00416.88
7.2.50.0090.00616.79
7.2.40.0000.01217.15
7.2.30.0070.01016.96
7.2.20.0040.01116.79
7.2.10.0110.00716.89
7.2.00.0020.01317.90
7.1.250.0030.01315.52
7.1.200.0080.00315.87
7.1.100.0090.00918.30
7.1.70.0050.00317.23
7.1.60.0070.01819.82
7.1.50.0030.01416.93
7.1.00.0000.08022.54
7.0.200.0080.00316.94
7.0.140.0000.07321.95
7.0.100.0030.05320.07
7.0.90.0130.07720.00
7.0.80.0070.08019.94
7.0.70.0130.03320.02
7.0.60.0030.07320.12
7.0.50.0000.04720.44
7.0.40.0030.04319.96
7.0.30.0030.04320.08
7.0.20.0070.04020.18
7.0.10.0000.04720.08
7.0.00.0030.05020.15
5.6.280.0000.07321.15
5.6.250.0100.07720.58
5.6.240.0100.08320.63
5.6.230.0330.02720.59
5.6.220.0130.05720.64
5.6.210.0100.04720.65
5.6.200.0170.07321.06
5.6.190.0070.04020.96
5.6.180.0030.04021.05
5.6.170.0030.04321.13
5.6.160.0070.04721.12
5.6.150.0030.04020.97
5.6.140.0000.04321.04
5.6.130.0070.07321.05
5.6.120.0030.04320.96
5.6.110.0070.04321.12
5.6.100.0030.04321.04
5.6.90.0100.04021.09
5.6.80.0030.04020.51
5.6.70.0130.05020.45
5.6.60.0030.06020.45
5.6.50.0030.04020.43
5.6.40.0030.04020.39
5.6.30.0030.04720.27
5.6.20.0070.06720.46
5.6.10.0030.04020.46
5.6.00.0070.04320.42
5.5.380.0000.08320.48
5.5.370.0070.07720.47
5.5.360.0100.06020.38
5.5.350.0030.04720.44
5.5.340.0100.04720.91
5.5.330.0030.04320.90
5.5.320.0000.04320.83
5.5.310.0070.04720.82
5.5.300.0100.06720.91
5.5.290.0070.08720.91
5.5.280.0030.04320.91
5.5.270.0070.04720.73
5.5.260.0000.04720.79
5.5.250.0030.04720.57
5.5.240.0070.03720.18
5.5.230.0000.04320.13
5.5.220.0100.03320.25
5.5.210.0000.04020.23
5.5.200.0070.03720.17
5.5.190.0070.04020.27
5.5.180.0000.04320.13
5.5.160.0030.04020.28
5.5.150.0000.04020.17
5.5.140.0070.04020.20
5.5.130.0100.04020.16
5.5.120.0030.03720.14
5.5.110.0030.05020.00
5.5.100.0030.05020.15
5.5.90.0030.06720.12
5.5.80.0000.07720.02
5.5.70.0070.03720.03
5.5.60.0070.07720.02
5.5.50.0100.07319.96
5.5.40.0070.08020.14
5.5.30.0070.08020.13
5.5.20.0030.05320.13
5.5.10.0170.07320.14
5.5.00.0070.08319.99
5.4.450.0100.04319.47
5.4.440.0030.04019.57
5.4.430.0100.03719.33
5.4.420.0100.03319.35
5.4.410.0030.04319.20
5.4.400.0070.04318.86
5.4.390.0030.03719.24
5.4.380.0070.03319.17
5.4.370.0130.03319.24
5.4.360.0030.04019.21
5.4.350.0100.05319.11
5.4.340.0070.03719.23
5.4.320.0000.04019.21
5.4.310.0030.03719.21
5.4.300.0030.03719.14
5.4.290.0030.06719.14
5.4.280.0170.02718.90
5.4.270.0000.04019.05
5.4.260.0030.03719.16
5.4.250.0030.07719.09
5.4.240.0070.07019.04
5.4.230.0030.08019.05
5.4.220.0030.08019.23
5.4.210.0070.06719.13
5.4.200.0070.06719.13
5.4.190.0170.07018.84
5.4.180.0030.08019.15
5.4.170.0030.08019.13
5.4.160.0100.07019.12
5.4.150.0000.07319.21
5.4.140.0030.06316.25
5.4.130.0030.04316.47
5.4.120.0170.06716.47
5.4.110.0070.05316.51
5.4.100.0030.07316.45
5.4.90.0030.04716.57
5.4.80.0070.03716.45
5.4.70.0070.06716.47
5.4.60.0170.06316.34
5.4.50.0000.08016.48
5.4.40.0100.06316.54
5.4.30.0100.07316.45
5.4.20.0070.07016.40
5.4.10.0000.05016.46
5.4.00.0070.07015.65
5.3.290.0030.04014.76
5.3.280.0130.07014.73
5.3.270.0070.04714.66
5.3.260.0030.08014.66
5.3.250.0030.07314.62
5.3.240.0070.07314.67
5.3.230.0170.05314.73
5.3.220.0030.08014.61
5.3.210.0000.08714.70
5.3.200.0100.07014.71
5.3.190.0030.08014.54
5.3.180.0070.07314.54
5.3.170.0030.05314.65
5.3.160.0070.07314.55
5.3.150.0130.07314.66
5.3.140.0070.07014.52
5.3.130.0100.07014.70
5.3.120.0100.07714.54
5.3.110.0030.08014.72
5.3.100.0100.07014.21
5.3.90.0100.06714.12
5.3.80.0070.07314.12
5.3.70.0070.08014.17
5.3.60.0070.07014.13
5.3.50.0100.07314.12
5.3.40.0100.07313.87
5.3.30.0030.06014.00
5.3.20.0100.06313.79
5.3.10.0100.06313.70
5.3.00.0070.06313.65
5.2.170.0030.06711.34
5.2.160.0100.05011.34
5.2.150.0100.05711.34
5.2.140.0070.04311.34
5.2.130.0030.06311.34
5.2.120.0070.06011.34
5.2.110.0030.06011.34
5.2.100.0000.06711.34
5.2.90.0070.06011.34
5.2.80.0000.06711.34
5.2.70.0070.04711.34
5.2.60.0130.05311.34
5.2.50.0030.04311.34
5.2.40.0030.04711.34
5.2.30.0070.04711.34
5.2.20.0030.06011.34
5.2.10.0030.06011.34
5.2.00.0070.05711.34
5.1.60.0100.04711.34
5.1.50.0030.05311.34
5.1.40.0070.05311.34
5.1.30.0100.04711.34
5.1.20.0070.04011.34
5.1.10.0070.03711.34
5.1.00.0000.05311.34
5.0.50.0030.05011.34
5.0.40.0100.02711.34
5.0.30.0030.06311.34
5.0.20.0100.02311.34
5.0.10.0000.04011.34
5.0.00.0070.05311.34
4.4.90.0000.02011.34
4.4.80.0070.03011.34
4.4.70.0000.03711.34
4.4.60.0000.03711.34
4.4.50.0000.02011.34
4.4.40.0030.05311.34
4.4.30.0030.03311.34
4.4.20.0000.04011.34
4.4.10.0070.03011.34
4.4.00.0070.05311.34
4.3.110.0000.03711.34
4.3.100.0000.03711.34
4.3.90.0170.02011.34
4.3.80.0070.03011.34
4.3.70.0030.03311.34
4.3.60.0070.03311.34
4.3.50.0030.03311.34
4.3.40.0030.03311.34
4.3.30.0070.03311.34
4.3.20.0030.03311.34
4.3.10.0070.03011.34
4.3.00.0000.03311.34

preferences:
78.08 ms | 401 KiB | 5 Q