3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('INT_SIGNED', 1); define('INT_LE', 2); function is32Bit() { // This is for max compatibility: // PHP_INT_MAX doesn't exist in PHP4 // current() *requires* a reference in PHP <5.1.0 (except 4.4.1, dafuq) $test = unpack('N', "\xFF\xFF\xFF\xFF"); return current($test) === -1; } function unpack_int32($str, $flags = 0) { // Make sure data is sane $str = (string) $str; $length = strlen($str); if ($length < 4) { return false; } else if ($length > 4) { $str = substr($str, 0, 4); } // Normalize to big endian and unpack to int32 if ($flags & INT_LE) { $str = strrev($str); } $result = unpack('N', $str); $result = current($result); // Sign and word size info $signBit = (bool) ($result & 0x80000000); $isSigned = (bool) ($flags & INT_SIGNED); $is32bit = is32Bit(); if ($signBit && $isSigned && !$is32bit) { // Left pad with set bits for negative numbers on 64-bit $result = (0x00000000FFFFFFFF << 32) | $result; } else if ($signBit && !$isSigned && $is32bit) { // Convert int32 to unsigned float $result = (($result & 0x7FFFFFFF) * 2) + ~$result + 1; } return $result; } function unpack_int64($str, $flags = 0) { // Make sure data is sane $str = (string) $str; $length = strlen($str); if ($length < 8) { return false; } else if ($length > 8) { $str = substr($str, 0, 8); } // Normalize to big endian and unpack to int32s if ($flags & INT_LE) { $str = strrev($str); } $int32s = array_values(unpack('N*', $str)); // Sign and word size info $signBit = (bool) ($int32s[0] & 0x80000000); $isSigned = (bool) ($flags & INT_SIGNED); $is32bit = is32Bit(); if ($is32bit) { if ($int32s[1] & 0x80000000) { // Convert second int32 to unsigned float $int32s[1] = (($int32s[1] & 0x7FFFFFFF) * 2) + ~$int32s[1] + 1; } if ($isSigned && $signBit) { // Negative $result = ($int32s[0] * pow(2, 32)) + $int32s[1]; } else { // Positive if ($signBit) { // Convert first int32 to unsigned float $int32s[0] = (($int32s[0] & 0x7FFFFFFF) * 2) + ~$int32s[0] + 1; } $result = ($int32s[0] * pow(2, 32)) + $int32s[1]; } } else { // Combine int32s into int64 $result = ($int32s[0] << 32) | $int32s[1]; if ($signBit && !$isSigned) { // Convert to negative $result = (($result & 0x7FFFFFFFFFFFFFFF) * 2) + ~$result + 1; } } return $result; } echo "int32:\n"; printf("%f\n", unpack_int32("\xFF\xFC\x00\x80")); printf("%f\n", unpack_int32("\xFF\xFC\x00\x80", INT_SIGNED)); printf("%f\n", unpack_int32("\xFF\xFC\x00\x80", INT_LE)); printf("%f\n", unpack_int32("\xFF\xFC\x00\x80", INT_LE | INT_SIGNED)); echo "\n"; echo "int64:\n"; printf("%f\n", unpack_int64("\xFF\xFF\xFF\xFC\x00\x00\x00\x80")); printf("%f\n", unpack_int64("\xFF\xFF\xFF\xFC\x00\x00\x00\x80", INT_SIGNED)); printf("%f\n", unpack_int64("\xFF\xFF\xFF\xFC\x00\x00\x00\x80", INT_LE)); printf("%f\n", unpack_int64("\xFF\xFF\xFF\xFC\x00\x00\x00\x80", INT_LE | INT_SIGNED));

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.0150.00018.70
8.3.30.0100.00319.04
8.3.20.0070.00020.33
8.3.10.0090.00023.48
8.3.00.0080.00019.18
8.2.170.0070.01119.09
8.2.160.0130.00722.96
8.2.150.0040.00425.66
8.2.140.0090.00624.66
8.2.130.0080.00026.16
8.2.120.0000.00820.71
8.2.110.0090.00022.13
8.2.100.0090.00317.91
8.2.90.0040.00419.27
8.2.80.0060.00317.97
8.2.70.0000.00917.49
8.2.60.0100.00018.05
8.2.50.0030.00618.07
8.2.40.0040.00420.07
8.2.30.0040.00418.45
8.2.20.0030.00517.75
8.2.10.0090.00018.23
8.2.00.0000.00817.85
8.1.270.0060.00324.00
8.1.260.0000.00726.35
8.1.250.0040.00428.09
8.1.240.0070.00323.97
8.1.230.0060.00618.96
8.1.220.0000.00817.74
8.1.210.0050.00318.77
8.1.200.0040.00817.13
8.1.190.0000.00817.22
8.1.180.0080.00018.10
8.1.170.0060.00318.66
8.1.160.0050.00222.06
8.1.150.0000.00718.74
8.1.140.0040.00417.48
8.1.130.0000.00717.83
8.1.120.0000.00717.44
8.1.110.0000.00817.42
8.1.100.0040.00417.40
8.1.90.0080.00417.51
8.1.80.0040.00417.48
8.1.70.0050.00317.38
8.1.60.0090.00017.52
8.1.50.0030.00517.43
8.1.40.0040.00417.63
8.1.30.0030.00617.65
8.1.20.0050.00317.57
8.1.10.0030.00617.69
8.1.00.0070.00017.42
8.0.300.0000.00718.77
8.0.290.0000.00716.88
8.0.280.0040.00418.39
8.0.270.0040.00417.31
8.0.260.0060.00017.37
8.0.250.0000.00717.02
8.0.240.0070.00017.00
8.0.230.0050.00317.02
8.0.220.0030.00316.93
8.0.210.0030.00316.83
8.0.200.0040.00416.93
8.0.190.0050.00316.91
8.0.180.0040.00417.00
8.0.170.0050.00216.93
8.0.160.0040.00416.88
8.0.150.0000.00716.78
8.0.140.0000.00716.89
8.0.130.0030.00313.33
8.0.120.0040.00416.84
8.0.110.0040.00416.94
8.0.100.0070.00016.86
8.0.90.0040.00416.82
8.0.80.0030.01316.96
8.0.70.0030.00517.01
8.0.60.0030.00616.79
8.0.50.0000.00716.93
8.0.30.0120.01117.17
8.0.20.0130.00517.40
8.0.10.0000.00716.96
8.0.00.0090.00916.99
7.4.330.0060.00015.00
7.4.320.0040.00416.60
7.4.300.0060.00016.58
7.4.290.0050.00216.54
7.4.280.0000.00816.54
7.4.270.0000.00716.65
7.4.260.0000.00716.63
7.4.250.0050.00316.60
7.4.240.0030.00416.63
7.4.230.0040.00416.71
7.4.220.0120.00616.56
7.4.210.0030.01016.74
7.4.200.0000.00716.30
7.4.190.0000.00816.78
7.4.160.0100.00616.55
7.4.150.0130.00617.40
7.4.140.0130.00817.86
7.4.130.0040.01316.73
7.4.120.0080.01116.50
7.4.110.0100.00716.46
7.4.100.0140.00916.59
7.4.90.0070.01016.44
7.4.80.0070.01719.39
7.4.70.0070.01116.70
7.4.60.0030.01616.54
7.4.50.0070.00016.44
7.4.40.0110.00616.75
7.4.30.0030.01316.70
7.4.00.0120.00314.89
7.3.330.0060.00013.27
7.3.320.0030.00213.22
7.3.310.0040.00416.42
7.3.300.0030.00316.38
7.3.290.0040.01116.46
7.3.280.0050.01516.43
7.3.270.0120.00617.40
7.3.260.0080.00916.64
7.3.250.0040.01416.60
7.3.240.0140.00716.44
7.3.230.0100.00716.70
7.3.210.0030.02016.45
7.3.200.0100.01019.39
7.3.190.0090.00916.67
7.3.180.0130.00316.63
7.3.170.0030.01216.55
7.3.160.0000.01616.39
7.3.120.0090.00614.92
7.2.330.0110.00716.44
7.2.320.0090.01216.93
7.2.310.0110.01416.77
7.2.300.0090.00916.88
7.2.290.0040.01516.73
7.2.00.0000.01218.98
7.1.200.0000.01515.89
7.1.100.0000.01218.42
7.1.70.0040.01117.19
7.1.60.0070.01719.70
7.1.50.0000.02316.92
7.1.00.0000.07022.46
7.0.200.0040.00416.80
7.0.140.0030.07022.09
7.0.60.0100.03720.07
7.0.50.0170.07017.95
7.0.40.0030.05320.41
7.0.30.0270.08020.23
7.0.20.0330.07720.25
7.0.10.0030.04320.12
7.0.00.0030.06720.10
5.6.280.0000.07720.79
5.6.210.0000.07720.54
5.6.200.0100.06018.21
5.6.190.0070.09020.39
5.6.180.0230.04320.61
5.6.170.0200.05020.55
5.6.160.0030.04720.39
5.6.150.0000.05018.19
5.6.140.0030.08718.21
5.6.130.0070.06318.28
5.6.120.0070.07021.12
5.6.110.0100.06721.04
5.6.100.0030.04720.98
5.6.90.0200.07021.00
5.6.80.0030.06320.47
5.5.350.0330.07020.41
5.5.340.0100.08018.00
5.5.330.0030.06720.42
5.5.320.0070.04320.27
5.5.310.0130.04720.36
5.5.300.0070.08017.95
5.5.290.0170.06717.99
5.5.280.0130.07320.80
5.5.270.0000.05020.87
5.5.260.0130.07020.77
5.5.250.0170.06720.72
5.5.240.0100.07320.10
5.4.450.0030.04019.54
5.4.440.0070.03719.57
5.4.430.0030.03719.30
5.4.420.0000.04719.14
5.4.410.0070.03319.20
5.4.400.0030.03718.93
5.4.390.0070.03719.24
5.4.380.0100.03019.12
5.4.370.0030.03719.23
5.4.360.0000.04319.16
5.4.350.0000.04019.24
5.4.340.0030.03719.20
5.4.320.0030.03718.92
5.4.310.0030.05718.98
5.4.300.0070.04319.24
5.4.290.0170.04719.24
5.4.280.0070.07318.85
5.4.270.0130.06719.11
5.4.260.0130.07318.86
5.4.250.0000.05018.86
5.4.240.0000.08018.84
5.4.230.0030.04318.85
5.4.220.0100.06318.84
5.4.210.0070.04019.11
5.4.200.0130.06718.86
5.4.190.0070.03318.99
5.4.180.0200.05718.99
5.4.170.0100.06719.23
5.4.160.0030.08318.96
5.4.150.0200.03718.84
5.4.140.0070.03316.34
5.4.130.0130.06716.37
5.4.120.0130.06716.34
5.4.110.0070.07316.48
5.4.100.0000.07716.34
5.4.90.0030.04016.48
5.4.80.0030.08016.43
5.4.70.0030.07716.53
5.4.60.0100.07316.27
5.4.50.0070.05716.46
5.4.40.0000.04016.31
5.4.30.0070.04316.38
5.4.20.0070.07316.43
5.4.10.0030.05716.28
5.4.00.0030.05015.74
5.3.290.0070.04014.65
5.3.280.0130.06314.55
5.3.270.0070.08014.65
5.3.260.0070.06314.79
5.3.250.0070.07714.71
5.3.240.0070.03714.65
5.3.230.0070.05014.68
5.3.220.0030.06714.66
5.3.210.0030.04714.54
5.3.200.0030.04714.63
5.3.190.0030.07314.76
5.3.180.0100.04014.52
5.3.170.0100.07314.64
5.3.160.0030.07014.60
5.3.150.0070.07014.62
5.3.140.0070.03714.75
5.3.130.0030.08014.64
5.3.120.0130.04714.64
5.3.110.0030.04714.47
5.3.100.0100.05014.21
5.3.90.0070.03714.21
5.3.80.0000.04014.06
5.3.70.0030.06314.21
5.3.60.0130.06714.04
5.3.50.0030.06313.96
5.3.40.0070.07313.94
5.3.30.0000.05013.91
5.3.20.0100.04313.73
5.3.10.0070.03313.66
5.3.00.0070.08013.71
5.2.170.0070.06011.13
5.2.160.0100.05311.19
5.2.150.0030.03711.25
5.2.140.0100.05711.15
5.2.130.0000.03311.14
5.2.120.0070.03711.11
5.2.110.0070.02311.03
5.2.100.0100.03311.10
5.2.90.0000.06311.30
5.2.80.0030.03011.18
5.2.70.0070.06011.29
5.2.60.0100.04711.09
5.2.50.0030.04010.95
5.2.40.0000.03711.00
5.2.30.0070.03311.06
5.2.20.0130.05011.07
5.2.10.0100.05710.86
5.2.00.0030.03310.76
5.1.60.0030.03310.18
5.1.50.0130.05010.09
5.1.40.0000.05710.00
5.1.30.0000.06310.55
5.1.20.0030.04710.51
5.1.10.0000.04310.25
5.1.00.0030.04010.08
5.0.50.0000.0508.57
5.0.40.0030.0438.43
5.0.30.0100.0608.39
5.0.20.0000.0278.21
5.0.10.0030.0438.21
5.0.00.0030.0678.32
4.4.90.0030.0278.07
4.4.80.0000.0378.07
4.4.70.0000.0378.07
4.4.60.0030.0378.07
4.4.50.0000.0178.07
4.4.40.0030.0238.07
4.4.30.0000.0408.07
4.4.20.0030.0338.07
4.4.10.0000.0278.07
4.4.00.0030.0338.07
4.3.110.0000.0378.07
4.3.100.0030.0178.07
4.3.90.0000.0408.07
4.3.80.0100.0438.07
4.3.70.0030.0378.07
4.3.60.0100.0278.07
4.3.50.0070.0338.07
4.3.40.0000.0478.07
4.3.30.0000.0208.07
4.3.20.0000.0378.07
4.3.10.0000.0178.07
4.3.00.0030.0338.07

preferences:
38.82 ms | 400 KiB | 5 Q