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++) { $output[$i] = chr(((ord($input[$i - $skip]) & $mask) >> $offsetr) | (ord($input[($i - $skip) + 1]) << $offsetl)); } /* 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.40.0160.00018.67
8.3.30.0070.00719.05
8.3.20.0080.00020.20
8.3.10.0040.00422.00
8.3.00.0040.00422.31
8.2.170.0110.00422.96
8.2.160.0060.00919.33
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0090.00926.16
8.2.120.0050.00319.23
8.2.110.0030.00721.92
8.2.100.0060.00619.57
8.2.90.0000.00819.35
8.2.80.0000.00817.97
8.2.70.0050.00317.75
8.2.60.0060.00318.16
8.2.50.0000.00818.07
8.2.40.0090.00018.34
8.2.30.0040.00818.20
8.2.20.0000.00817.76
8.2.10.0040.00419.51
8.2.00.0040.00417.77
8.1.270.0030.00522.10
8.1.260.0110.00026.35
8.1.250.0070.00028.09
8.1.240.0000.00823.92
8.1.230.0070.00419.00
8.1.220.0060.00317.77
8.1.210.0040.00418.77
8.1.200.0030.00617.35
8.1.190.0030.00617.53
8.1.180.0060.00318.10
8.1.170.0060.00318.61
8.1.160.0070.00022.06
8.1.150.0000.00718.59
8.1.140.0070.00017.50
8.1.130.0040.00417.77
8.1.120.0040.00417.44
8.1.110.0030.00517.39
8.1.100.0040.00417.38
8.1.90.0040.00417.44
8.1.80.0000.00817.52
8.1.70.0070.00017.43
8.1.60.0000.00917.53
8.1.50.0000.00817.60
8.1.40.0050.00217.55
8.1.30.0040.00417.69
8.1.20.0060.00317.68
8.1.10.0000.00817.49
8.1.00.0080.00017.54
8.0.300.0000.00718.77
8.0.290.0070.00017.16
8.0.280.0080.00018.56
8.0.270.0000.00717.36
8.0.260.0000.00716.78
8.0.250.0030.00316.97
8.0.240.0000.00716.98
8.0.230.0070.00016.85
8.0.220.0040.00416.84
8.0.210.0030.00316.98
8.0.200.0070.00017.00
8.0.190.0080.00016.93
8.0.180.0040.00416.94
8.0.170.0000.00716.94
8.0.160.0070.00016.98
8.0.150.0070.00016.88
8.0.140.0040.00416.80
8.0.130.0030.00313.32
8.0.120.0040.00416.81
8.0.110.0050.00216.84
8.0.100.0030.00516.79
8.0.90.0050.00316.93
8.0.80.0070.01016.91
8.0.70.0000.00716.82
8.0.60.0070.00017.00
8.0.50.0040.00416.80
8.0.30.0090.01017.40
8.0.20.0090.00917.46
8.0.10.0060.00317.08
8.0.00.0140.00716.86
7.4.330.0030.00315.00
7.4.320.0050.00216.68
7.4.300.0060.00016.62
7.4.290.0000.00716.58
7.4.280.0030.00316.54
7.4.270.0000.00716.55
7.4.260.0030.00416.52
7.4.250.0000.00716.57
7.4.240.0040.00416.54
7.4.230.0030.00316.74
7.4.220.0070.01416.56
7.4.210.0020.01416.50
7.4.200.0040.00416.51
7.4.190.0070.00016.50
7.4.160.0090.00616.61
7.4.150.0060.01117.40
7.4.140.0080.00817.86
7.4.130.0110.00916.49
7.4.120.0090.01016.44
7.4.110.0140.00316.61
7.4.100.0060.01216.63
7.4.90.0100.00716.61
7.4.80.0080.01119.39
7.4.70.0030.01416.57
7.4.60.0120.00916.44
7.4.50.0030.00316.31
7.4.40.0030.01322.77
7.4.30.0080.00816.64
7.4.10.0090.00915.05
7.4.00.0080.00815.11
7.3.330.0000.00613.42
7.3.320.0050.00013.16
7.3.310.0030.00616.22
7.3.300.0070.00016.41
7.3.290.0090.00616.39
7.3.280.0080.00916.40
7.3.270.0090.00917.40
7.3.260.0100.00716.67
7.3.250.0120.00516.48
7.3.240.0100.01316.63
7.3.230.0150.00316.67
7.3.210.0130.00316.48
7.3.200.0130.01019.39
7.3.190.0070.01016.67
7.3.180.0060.01016.73
7.3.170.0100.00716.31
7.3.160.0060.01016.45
7.3.130.0100.00315.17
7.3.120.0080.00715.11
7.3.110.0030.01614.61
7.3.100.0030.00814.72
7.3.90.0000.00814.96
7.3.80.0100.00714.95
7.3.70.0060.01014.89
7.3.60.0040.01114.83
7.3.50.0060.00714.73
7.3.40.0070.00714.90
7.3.30.0090.00614.75
7.3.20.0030.01716.44
7.3.10.0070.00716.67
7.3.00.0080.00516.75
7.2.330.0070.01116.82
7.2.320.0060.01216.73
7.2.310.0130.01016.51
7.2.300.0150.00916.82
7.2.290.0070.01116.88
7.2.260.0160.00015.14
7.2.250.0000.01815.16
7.2.240.0100.00315.07
7.2.230.0000.01715.27
7.2.220.0040.00815.04
7.2.210.0070.00715.04
7.2.200.0060.00915.20
7.2.190.0030.00715.24
7.2.180.0040.00415.27
7.2.170.0030.00715.19
7.2.160.0000.02015.19
7.2.150.0100.00716.92
7.2.140.0070.01117.08
7.2.130.0080.00517.00
7.2.120.0040.01116.81
7.2.110.0080.00717.07
7.2.100.0070.00516.92
7.2.90.0060.01317.05
7.2.80.0090.00716.88
7.2.70.0110.00617.04
7.2.60.0020.01116.89
7.2.50.0090.00216.89
7.2.40.0120.00216.90
7.2.30.0000.01317.03
7.2.20.0040.00816.83
7.2.10.0040.00716.91
7.2.00.0070.00817.64
7.1.330.0000.00815.93
7.1.320.0000.01015.82
7.1.310.0030.01416.10
7.1.300.0090.00315.59
7.1.290.0060.00615.80
7.1.280.0030.00916.03
7.1.270.0060.00915.70
7.1.260.0030.01015.80
7.1.250.0030.01115.89
7.1.240.0040.01115.70
7.1.230.0040.00715.89
7.1.220.0070.00415.89
7.1.210.0160.00315.96
7.1.200.0000.01315.88
7.1.190.0070.00815.98
7.1.180.0000.01015.61
7.1.170.0030.01215.93
7.1.160.0100.00315.92
7.1.150.0120.00615.89
7.1.140.0000.01715.89
7.1.130.0030.00615.68
7.1.120.0100.00315.70
7.1.110.0030.00615.74
7.1.100.0020.01317.00
7.1.90.0080.00815.84
7.1.80.0030.01315.59
7.1.70.0070.00516.54
7.1.60.0080.01117.82
7.1.50.0030.01116.28
7.1.40.0060.01215.87
7.1.30.0070.00715.73
7.1.20.0090.00415.75
7.1.10.0000.01015.61
7.1.00.0050.04219.05
7.0.330.0000.01415.51
7.0.320.0030.01015.07
7.0.310.0040.00815.22
7.0.300.0060.00915.32
7.0.290.0030.01015.46
7.0.280.0060.00615.40
7.0.270.0000.00915.50
7.0.260.0040.00415.43
7.0.250.0040.00815.34
7.0.240.0040.00815.34
7.0.230.0070.00715.42
7.0.220.0060.01315.45
7.0.210.0040.00715.40
7.0.200.0030.00716.23
7.0.190.0060.00615.54
7.0.180.0090.00615.14
7.0.170.0070.01115.45
7.0.160.0080.00315.59
7.0.150.0070.00715.59
7.0.140.0080.03518.76
7.0.130.0030.00915.58
7.0.120.0090.00315.21
7.0.110.0040.01115.39
7.0.100.0060.00315.61
7.0.90.0060.00315.50
7.0.80.0000.01415.48
7.0.70.0000.00815.45
7.0.60.0090.04417.61
7.0.50.0060.04316.79
7.0.40.0030.02816.79
7.0.30.0200.02416.84
7.0.20.0100.02516.91
7.0.10.0110.02516.88
7.0.00.0070.04116.77
5.6.400.0070.00714.61
5.6.390.0070.00714.39
5.6.380.0130.00314.61
5.6.370.0100.00614.70
5.6.360.0100.00614.47
5.6.350.0070.00414.39
5.6.340.0020.01414.06
5.6.330.0040.01214.16
5.6.320.0040.01114.73
5.6.310.0030.01014.58
5.6.300.0000.01414.73
5.6.290.0090.00614.36
5.6.280.0090.00614.67
5.6.270.0100.00014.45
5.6.260.0030.01014.59
5.6.250.0080.00014.32
5.6.240.0120.00314.45
5.6.230.0060.01014.52
5.6.220.0000.01114.56
5.6.210.0080.02717.60
5.6.200.0080.03816.31
5.6.190.0080.03517.74
5.6.180.1920.02417.40
5.6.170.0150.04717.56
5.6.160.0050.03917.52
5.6.150.0100.03816.24
5.6.140.0050.02916.25
5.6.130.0110.04016.42
5.6.120.0070.02917.75
5.6.110.0050.03817.89
5.6.100.0030.02517.63
5.6.90.0030.04317.79
5.6.80.0050.03517.56
5.6.70.0150.04017.31
5.6.60.0070.00714.20
5.6.50.0000.01014.25
5.6.40.0040.00814.66
5.6.30.0060.00614.34
5.6.20.0040.00714.16
5.6.10.0070.00714.50
5.6.00.0030.00914.32
5.5.380.0090.00614.58
5.5.370.0060.01014.38
5.5.360.0030.01014.25
5.5.350.0050.04417.32
5.5.340.0030.04716.25
5.5.330.0050.03017.22
5.5.320.0070.02817.27
5.5.310.0100.02117.26
5.5.300.0050.02216.20
5.5.290.0030.05516.17
5.5.280.0110.04517.55
5.5.270.0100.04217.49
5.5.260.0080.04517.60
5.5.250.0130.03017.46
5.5.240.0050.04617.29
5.5.230.0040.00814.25
5.5.220.0000.01114.21
5.5.210.0060.00614.06
5.5.200.0060.00814.11
5.5.190.0030.01014.47
5.5.180.0030.00714.24
5.5.170.0000.01414.33
5.5.160.0060.00614.43
5.5.150.0030.01014.28
5.5.140.0080.00614.16
5.5.130.0070.00713.91
5.5.120.0040.00814.32
5.5.110.0070.00714.15
5.5.100.0090.00014.46
5.5.90.0070.00414.28
5.5.80.0040.01114.05
5.5.70.0040.00414.18
5.5.60.0000.01114.05
5.5.50.0040.01114.18
5.5.40.0070.00714.23
5.5.30.0080.00414.29
5.5.20.0000.00814.27
5.5.10.0100.00714.56
5.5.00.0000.01314.57
5.4.450.0140.02215.41
5.4.440.0130.03515.29
5.4.430.0120.02315.18
5.4.420.0150.01815.21
5.4.410.0100.02715.34
5.4.400.0170.03515.11
5.4.390.0130.02315.19
5.4.380.0120.01915.09
5.4.370.0130.02315.13
5.4.360.0100.02215.16
5.4.350.0120.02215.17
5.4.340.0130.02015.21
5.4.330.0030.00711.24
5.4.320.0120.02215.01
5.4.310.0100.02214.99
5.4.300.0130.02014.92
5.4.290.0100.02314.97
5.4.280.0070.03115.23
5.4.270.0170.03315.25
5.4.260.0120.02115.13
5.4.250.0140.01814.95
5.4.240.0100.02015.00
5.4.230.0070.02515.22
5.4.220.0100.02015.05
5.4.210.0100.02315.17
5.4.200.0080.04315.13
5.4.190.0110.03215.11
5.4.180.0120.02215.14
5.4.170.0100.02714.81
5.4.160.0110.02315.16
5.4.150.0120.03714.92
5.4.140.0120.02313.81
5.4.130.0130.02213.73
5.4.120.0030.02713.70
5.4.110.0080.02514.05
5.4.100.0190.01813.73
5.4.90.0210.02813.85
5.4.80.0100.02813.67
5.4.70.0140.01913.78
5.4.60.0160.02613.77
5.4.50.0200.02313.66
5.4.40.0170.03413.53
5.4.30.0150.02613.92
5.4.20.0230.03113.88
5.4.10.0200.03313.93
5.4.00.0190.02613.55
5.3.290.0080.02312.67
5.3.280.0120.02412.63
5.3.270.0100.02312.60
5.3.260.0110.02012.68
5.3.250.0100.02412.69
5.3.240.0100.02212.49
5.3.230.0080.02312.71
5.3.220.0100.02312.53
5.3.210.0120.02212.54
5.3.200.0190.03312.56
5.3.190.0120.03712.57
5.3.180.0080.02912.58
5.3.170.0130.02212.54
5.3.160.0110.02312.66
5.3.150.0130.02012.66
5.3.140.0150.04112.65
5.3.130.0180.02512.78
5.3.120.0160.02612.77
5.3.110.0170.04012.51
5.3.100.0180.03312.36
5.3.90.0130.02512.39
5.3.80.0130.02512.37
5.3.70.0140.02112.15
5.3.60.0110.02612.29
5.3.50.0170.02412.37
5.3.40.0100.03612.26
5.3.30.0170.03312.43
5.3.20.0100.03112.16
5.3.10.0130.02212.02
5.3.00.0130.01912.14
5.2.170.0270.04311.90
5.2.160.0170.03711.90
5.2.150.0430.03011.90
5.2.140.0230.04011.90
5.2.130.0130.04311.90
5.2.120.0200.05011.90
5.2.110.0170.02711.90
5.2.100.0130.03011.90
5.2.90.0200.04711.90
5.2.80.0170.02711.90
5.2.70.0170.02711.90
5.2.60.0130.04711.90
5.2.50.0200.03311.90
5.2.40.0200.04711.90
5.2.30.0200.04711.90
5.2.20.0200.04311.90
5.2.10.0130.04011.90
5.2.00.0200.05311.90
5.1.60.0200.05011.90
5.1.50.0230.04311.90
5.1.40.0230.03711.90
5.1.30.0200.05011.90
5.1.20.0270.04311.90
5.1.10.0170.05311.90
5.1.00.0170.05711.90
5.0.50.0130.03011.90
5.0.40.0130.02711.90
5.0.30.0170.04011.90
5.0.20.0070.02011.90
5.0.10.0070.03011.90
5.0.00.0130.03711.90
4.4.90.0070.01311.90
4.4.80.0100.01311.90
4.4.70.0100.03311.90
4.4.60.0130.02311.90
4.4.50.0070.03011.90
4.4.40.0100.03311.90
4.4.30.0130.02311.90
4.4.20.0130.02311.90
4.4.10.0100.01311.90
4.4.00.0070.05711.90
4.3.110.0130.02311.90
4.3.100.0070.02711.90
4.3.90.0130.03711.90
4.3.80.0100.04311.90
4.3.70.0130.01011.90
4.3.60.0070.01711.90
4.3.50.0070.01711.90
4.3.40.0170.02011.90
4.3.30.0030.01711.90
4.3.20.0030.01711.90
4.3.10.0030.02711.90
4.3.00.0030.01311.90

preferences:
40.14 ms | 400 KiB | 5 Q