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; $output = str_pad('', $inputlen + 1, "\x00"); for ($i = 0; $i < $skip; $i++) { $output[$i] = $signbits; } if ($offsetr == 0) { /* Shifting multiples of 8 allows us to simply copy the relevant bytes */ for ($i = $skip; $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); } */ } $input = "abc\x00"; $bits = 8; 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.0130.00618.56
8.3.50.0160.00521.15
8.3.40.0170.00018.67
8.3.30.0080.00619.27
8.3.20.0070.00020.21
8.3.10.0090.00021.99
8.3.00.0050.00322.48
8.2.180.0160.00016.75
8.2.170.0070.00722.96
8.2.160.0090.00919.29
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0140.00026.16
8.2.120.0110.00017.63
8.2.110.0000.00922.20
8.2.100.0090.00618.09
8.2.90.0080.00019.26
8.2.80.0000.00818.05
8.2.70.0030.00617.63
8.2.60.0000.00818.16
8.2.50.0080.00018.07
8.2.40.0040.00418.34
8.2.30.0040.00418.20
8.2.20.0000.00817.60
8.2.10.0000.00817.69
8.2.00.0060.00317.63
8.1.280.0140.00025.92
8.1.270.0090.00022.14
8.1.260.0000.00726.35
8.1.250.0070.00028.09
8.1.240.0090.00023.84
8.1.230.0080.00419.07
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0060.00317.35
8.1.190.0040.00417.40
8.1.180.0030.00620.56
8.1.170.0090.00318.60
8.1.160.0000.00722.03
8.1.150.0040.00418.70
8.1.140.0040.00417.42
8.1.130.0030.00717.75
8.1.120.0040.00417.38
8.1.110.0080.00017.46
8.1.100.0070.00017.45
8.1.90.0050.00217.39
8.1.80.0080.00017.44
8.1.70.0000.00717.46
8.1.60.0000.00817.61
8.1.50.0000.00717.60
8.1.40.0000.00717.42
8.1.30.0050.00217.65
8.1.20.0030.00517.59
8.1.10.0070.00017.61
8.1.00.0000.00817.38
8.0.300.0000.00718.77
8.0.290.0000.00717.16
8.0.280.0050.00218.38
8.0.270.0030.00317.15
8.0.260.0030.00316.79
8.0.250.0000.00716.98
8.0.240.0000.01017.01
8.0.230.0040.00416.90
8.0.220.0000.00716.81
8.0.210.0000.00716.79
8.0.200.0030.00316.95
8.0.190.0040.00416.95
8.0.180.0040.00416.95
8.0.170.0050.00316.84
8.0.160.0050.00216.90
8.0.150.0000.00716.89
8.0.140.0080.00416.81
8.0.130.0000.00613.38
8.0.120.0030.00616.87
8.0.110.0030.00516.84
8.0.100.0000.00716.90
8.0.90.0040.00416.97
8.0.80.0060.00916.87
8.0.70.0040.00416.87
8.0.60.0000.00716.90
8.0.50.0000.00716.80
8.0.30.0110.00816.98
8.0.20.0130.00917.45
8.0.10.0040.00416.88
8.0.00.0140.00716.63
7.4.330.0050.00015.00
7.4.320.0030.00316.57
7.4.300.0040.00416.43
7.4.290.0070.00016.37
7.4.280.0030.00316.60
7.4.270.0030.00316.60
7.4.260.0000.00716.45
7.4.250.0000.00716.62
7.4.240.0000.00716.59
7.4.230.0070.00016.57
7.4.220.0030.01416.47
7.4.210.0090.00516.63
7.4.200.0000.00716.49
7.4.190.0000.00716.57
7.4.160.0080.00816.51
7.4.150.0130.00517.40
7.4.140.0100.01017.86
7.4.130.0140.00916.45
7.4.120.0120.00716.60
7.4.110.0100.01016.57
7.4.100.0110.00516.41
7.4.90.0060.01216.64
7.4.80.0190.00319.39
7.4.70.0090.00916.43
7.4.60.0110.00616.55
7.4.50.0000.00816.55
7.4.40.0090.00522.77
7.4.30.0030.01316.31
7.4.00.0030.00714.74
7.3.330.0020.00213.33
7.3.320.0050.00013.38
7.3.310.0000.00716.47
7.3.300.0000.00816.39
7.3.290.0110.00316.43
7.3.280.0100.00716.40
7.3.270.0070.01017.40
7.3.260.0060.01016.40
7.3.250.0130.00616.54
7.3.240.0110.00816.60
7.3.230.0030.01716.39
7.3.210.0070.01316.39
7.3.200.0120.00916.43
7.3.190.0130.01116.64
7.3.180.0120.00916.34
7.3.170.0070.00916.36
7.3.160.0120.00316.31
7.3.120.0000.01014.89
7.2.330.0090.00916.88
7.2.320.0070.01616.48
7.2.310.0130.00716.56
7.2.300.0100.00616.81
7.2.290.0070.01016.53
7.2.60.0130.00017.02
7.2.00.0030.01419.75
7.1.200.0130.00715.91
7.1.100.0070.01017.99
7.1.70.0000.01117.13
7.1.60.0190.00619.82
7.1.50.0070.01417.02
7.1.00.0000.03722.43
7.0.200.0070.00016.80
7.0.140.0070.07021.95
7.0.60.0100.03320.02
7.0.50.0100.07317.87
7.0.40.0030.09320.02
7.0.30.0270.04720.16
7.0.20.0270.04320.09
7.0.10.0300.04720.09
7.0.00.0030.08720.23
5.6.280.0030.07321.00
5.6.210.0130.07320.64
5.6.200.0030.04018.19
5.6.190.0000.08720.64
5.6.180.3700.03320.33
5.6.170.0300.06720.51
5.6.160.0030.04320.46
5.6.150.0130.07718.24
5.6.140.0030.04018.27
5.6.130.0100.05018.15
5.6.120.0100.05321.08
5.6.110.0130.06721.06
5.6.100.0070.08321.15
5.6.90.0170.04020.96
5.6.80.0100.07720.45
5.6.70.0200.02720.45
5.5.350.0100.08020.34
5.5.340.0070.08317.98
5.5.330.0130.05720.47
5.5.320.0170.04320.34
5.5.310.0230.08020.37
5.5.300.0000.04017.97
5.5.290.0070.04717.98
5.5.280.0100.08020.89
5.5.270.0030.04020.91
5.5.260.0100.08720.98
5.5.250.0070.04020.71
5.5.240.0070.08020.36
5.4.450.0300.05719.33
5.4.440.0430.04019.63
5.4.430.0330.03319.29
5.4.420.0370.07319.19
5.4.410.0300.03319.43
5.4.400.0300.07019.20
5.4.390.0230.05319.05
5.4.380.0370.06719.14
5.4.370.0430.06319.05
5.4.360.0200.04319.17
5.4.350.0330.06319.20
5.4.340.0300.05319.21
5.4.320.0300.03718.98
5.4.310.0370.04019.23
5.4.300.0330.04318.87
5.4.290.0370.06319.00
5.4.280.0270.04019.07
5.4.270.0370.04719.05
5.4.260.0330.03718.94
5.4.250.0470.06019.07
5.4.240.0430.04719.08
5.4.230.0470.06719.19
5.4.220.0430.06719.13
5.4.210.0470.06018.97
5.4.200.0330.04019.20
5.4.190.0430.06718.94
5.4.180.0470.06018.86
5.4.170.0400.03719.30
5.4.160.0400.03719.18
5.4.150.0430.04318.93
5.4.140.0370.03016.39
5.4.130.0430.06716.51
5.4.120.0400.03016.55
5.4.110.0470.06016.24
5.4.100.0500.06316.57
5.4.90.0400.05316.33
5.4.80.0500.03716.41
5.4.70.0530.06016.59
5.4.60.0470.06016.25
5.4.50.0430.06316.24
5.4.40.0400.06716.42
5.4.30.0400.05016.59
5.4.20.0270.05016.50
5.4.10.0330.03716.32
5.4.00.0670.01716.17
5.3.290.0330.07316.17
5.3.280.0470.07016.17
5.3.270.0500.04716.17
5.3.260.0330.06016.17
5.3.250.0470.06716.17
5.3.240.0330.03716.17
5.3.230.0370.06716.17
5.3.220.0200.04316.17
5.3.210.0500.05316.17
5.3.200.0270.04716.17
5.3.190.0370.06716.17
5.3.180.0300.07016.17
5.3.170.0270.06016.17
5.3.160.0500.05716.17
5.3.150.0500.06316.17
5.3.140.0400.03716.17
5.3.130.0530.06016.17
5.3.120.0270.05316.17
5.3.110.0330.07016.17
5.3.100.0330.05016.17
5.3.90.0370.05716.17
5.3.80.0370.06316.17
5.3.70.0430.05716.17
5.3.60.0400.04316.17
5.3.50.0530.05716.17
5.3.40.0430.05016.17
5.3.30.0370.04016.17
5.3.20.0370.03016.17
5.3.10.0530.05016.17
5.3.00.0500.06016.17
5.2.170.0330.03316.17
5.2.160.0270.03016.17
5.2.150.0330.05316.17
5.2.140.0400.05716.17
5.2.130.0370.05016.17
5.2.120.0330.04316.17
5.2.110.0400.05316.17
5.2.100.0330.03716.17
5.2.90.0330.03016.17
5.2.80.0300.06016.17
5.2.70.0270.03716.17
5.2.60.0370.04716.17
5.2.50.0330.05716.17
5.2.40.0300.05016.17
5.2.30.0200.04016.17
5.2.20.0270.06316.17
5.2.10.0230.05716.17
5.2.00.0300.04316.17
5.1.60.0300.03016.17
5.1.50.0230.03016.17
5.1.40.0230.03016.17
5.1.30.0230.05016.17
5.1.20.0300.05316.17
5.1.10.0230.04316.17
5.1.00.0270.02016.17
5.0.50.0170.04316.17
5.0.40.0100.02016.17
5.0.30.0130.03016.17
5.0.20.0100.04316.17
5.0.10.0170.03016.17
5.0.00.0130.04316.17
4.4.90.0130.02016.17
4.4.80.0100.02016.17
4.4.70.0170.03016.17
4.4.60.0170.03316.17
4.4.50.0200.03016.17
4.4.40.0130.05716.17
4.4.30.0200.02316.17
4.4.20.0170.03316.17
4.4.10.0270.01016.17
4.4.00.0170.03016.17
4.3.110.0170.03316.17
4.3.100.0200.03016.17
4.3.90.0130.03316.17
4.3.80.0130.03716.17
4.3.70.0130.02316.17
4.3.60.0170.02716.17
4.3.50.0170.03016.17
4.3.40.0100.03016.17
4.3.30.0070.03716.17
4.3.20.0070.02716.17
4.3.10.0070.04016.17
4.3.00.0030.02016.17

preferences:
41.85 ms | 401 KiB | 5 Q