3v4l.org

run code in 300+ PHP versions simultaneously
<?php function normalise_ip($address) { if (preg_match('/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/', $address, $matches)) { // IPv4 address $num = 0; for ($i = 1; $i <= 4; $i++) { $octet = (int) $matches[$i]; if ($octet > 255) { return false; } $num |= $octet << ((4 - $i) * 8); } return sprintf('00000000000000000000ffff%04x', $num); } else if (preg_match('/\[?((?:[0-9a-f]{1,4}:|::)+[0-9a-f]{1,4})]?/i', strtolower($address), $matches)) { // IPv6 address $parts = explode(':', $matches[1]); $numParts = count($parts); if ($parts[0] === '') { array_splice($parts, 0, 2, array_fill(0, 8 - ($numParts - 2), '0000')); } else if ($parts[$numParts - 1] === '') { echo "end\n"; array_splice($parts, $numParts - 2, 2, array_fill(0, 8 - ($numParts - 2), '0000')); } else { foreach ($parts as $i => $part) { if ($part === '') { array_splice($parts, $i, 1, array_fill(0, 8 - ($numParts - 1), '0000')); } } } foreach ($parts as &$part) { $part = sprintf('%04s', $part); } return implode('', $parts); } else { // invalid return false; } } echo normalise_ip('192.168.0.1') . "\n"; echo normalise_ip('::ffff:C0A8:0001') . "\n"; echo normalise_ip('[::ffff:C0A8:0001]') . "\n"; echo normalise_ip('[C0A8:0001::]') . "\n";

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.0180.00418.68
8.3.50.0120.00821.33
8.3.40.0120.00419.01
8.3.30.0170.00020.33
8.3.20.0060.00318.88
8.3.10.0060.00321.27
8.3.00.0090.00019.75
8.2.180.0130.00316.88
8.2.170.0090.00622.96
8.2.160.0070.00722.21
8.2.150.0060.01324.18
8.2.140.0040.00424.66
8.2.130.0030.00626.16
8.2.120.0070.00321.16
8.2.110.0060.00319.39
8.2.100.0130.00318.03
8.2.90.0000.00819.39
8.2.80.0080.00018.00
8.2.70.0040.00717.85
8.2.60.0000.00818.05
8.2.50.0000.00818.10
8.2.40.0090.00020.09
8.2.30.0040.00421.30
8.2.20.0020.00618.00
8.2.10.0030.00518.02
8.2.00.0080.00017.84
8.1.280.0180.00425.92
8.1.270.0030.00623.99
8.1.260.0170.00326.35
8.1.250.0080.00028.09
8.1.240.0060.00323.86
8.1.230.0040.00717.83
8.1.220.0050.00317.74
8.1.210.0000.00818.77
8.1.200.0070.00317.60
8.1.190.0000.00817.60
8.1.180.0000.00818.10
8.1.170.0040.00418.80
8.1.160.0030.00518.98
8.1.150.0050.00318.79
8.1.140.0040.00417.71
8.1.130.0030.00317.88
8.1.120.0000.00717.58
8.1.110.0000.00717.69
8.1.100.0050.00317.70
8.1.90.0050.00317.59
8.1.80.0000.00717.55
8.1.70.0000.00717.64
8.1.60.0030.01017.73
8.1.50.0030.00517.70
8.1.40.0000.00817.64
8.1.30.0040.00417.84
8.1.20.0000.00817.81
8.1.10.0000.00817.85
8.1.00.0030.00617.71
8.0.300.0020.00518.77
8.0.290.0090.00017.00
8.0.280.0040.00418.53
8.0.270.0000.00817.41
8.0.260.0000.00717.11
8.0.250.0070.00017.18
8.0.240.0030.00517.06
8.0.230.0070.00017.07
8.0.220.0000.00717.18
8.0.210.0060.00317.10
8.0.200.0000.00717.03
8.0.190.0000.00917.16
8.0.180.0040.00416.96
8.0.170.0070.00017.05
8.0.160.0050.00517.18
8.0.150.0040.00417.09
8.0.140.0080.00317.08
8.0.130.0030.00313.41
8.0.120.0050.00316.95
8.0.110.0000.00816.99
8.0.100.0080.00016.91
8.0.90.0040.00416.93
8.0.80.0140.00617.09
8.0.70.0000.00817.18
8.0.60.0040.00417.11
8.0.50.0050.00317.17
8.0.30.0110.01117.32
8.0.20.0090.01317.40
8.0.10.0080.00017.08
8.0.00.0060.01117.03
7.4.330.0000.00516.77
7.4.320.0080.00016.66
7.4.300.0040.00416.84
7.4.290.0040.00416.83
7.4.280.0060.00316.85
7.4.270.0000.00716.89
7.4.260.0050.00013.60
7.4.250.0030.00516.78
7.4.240.0030.00516.74
7.4.230.0030.00316.77
7.4.220.0030.01816.86
7.4.210.0050.01016.82
7.4.200.0040.00416.91
7.4.190.0040.00417.04
7.4.160.0060.01016.93
7.4.150.0100.01017.40
7.4.140.0080.01317.86
7.4.130.0060.01216.73
7.4.120.0110.00716.71
7.4.110.0030.01716.88
7.4.100.0130.00616.68
7.4.90.0070.01116.95
7.4.80.0220.00019.39
7.4.70.0100.00716.59
7.4.60.0130.01016.85
7.4.50.0030.00616.59
7.4.40.0120.00022.77
7.4.30.0000.02016.70
7.4.00.0090.00515.23
7.3.330.0030.00313.32
7.3.320.0060.00013.46
7.3.310.0000.00716.39
7.3.300.0040.00416.48
7.3.290.0160.00316.54
7.3.280.0100.00816.50
7.3.270.0090.00917.40
7.3.260.0120.01018.24
7.3.250.0070.01416.67
7.3.240.0100.00716.61
7.3.230.0080.00816.83
7.3.210.0090.00616.63
7.3.200.0060.01619.39
7.3.190.0100.00716.61
7.3.180.0040.01216.87
7.3.170.0000.01716.78
7.3.160.0110.00716.69
7.3.120.0060.00915.12
7.3.110.0060.01215.19
7.3.100.0090.00614.86
7.3.90.0040.01115.10
7.3.80.0120.00314.79
7.3.70.0030.01414.84
7.3.60.0070.00714.94
7.3.50.0070.00714.88
7.3.40.0100.00714.59
7.3.30.0060.00615.01
7.3.20.0030.00916.82
7.3.10.0130.00316.81
7.3.00.0070.00716.77
7.2.330.0030.01517.04
7.2.320.0110.00617.11
7.2.310.0110.00816.85
7.2.300.0130.00316.91
7.2.290.0100.00617.00
7.2.250.0140.00415.09
7.2.240.0140.00715.16
7.2.230.0070.01315.16
7.2.220.0000.01015.46
7.2.210.0090.00615.11
7.2.200.0060.01014.86
7.2.190.0000.01214.92
7.2.180.0060.00915.11
7.2.170.0030.01014.77
7.2.00.0000.01719.87
7.1.330.0070.00715.55
7.1.320.0000.01315.94
7.1.310.0080.00416.04
7.1.300.0060.00615.84
7.1.290.0040.01115.80
7.1.280.0070.00315.59
7.1.270.0050.00515.93
7.1.260.0110.00415.90
7.1.100.0070.00718.12
7.1.70.0000.01018.73
7.1.60.0070.00418.73
7.1.50.0040.01118.73
7.1.40.0040.00718.73
7.1.30.0060.00618.73
7.1.20.0140.00718.73
7.1.10.0030.00518.73
7.1.00.0000.00918.73
7.0.200.0090.00318.73
7.0.190.0070.01018.73
7.0.180.0030.00518.73
7.0.170.0060.00318.73
7.0.160.0030.01218.73
7.0.150.0000.01018.73
7.0.140.0050.00318.73
7.0.130.0000.00718.73
7.0.120.0040.00418.73
7.0.110.0000.01218.73
7.0.100.0060.00918.73
7.0.90.0000.01418.73
7.0.80.0070.01618.73
7.0.70.0030.00718.73
7.0.60.0030.00518.73
7.0.50.0000.00818.73
7.0.40.0000.00818.73
7.0.30.0030.00618.73
7.0.20.0040.00418.73
7.0.10.0000.00818.73
7.0.00.0040.00418.73
5.6.300.0030.04420.96
5.6.290.0040.04220.80
5.6.280.0030.04020.88
5.6.270.0000.04420.99
5.6.260.0030.04021.09
5.6.250.0130.05620.78
5.6.240.0030.04521.00
5.6.230.0070.08220.99
5.6.220.0030.04420.95
5.6.210.0000.04320.98
5.6.200.0070.08621.04
5.6.190.0070.04320.85
5.6.180.0100.05120.88
5.6.170.0030.04120.98
5.6.160.0070.04520.97
5.6.150.0030.04221.06
5.6.140.0100.03521.04
5.6.130.0070.03721.06
5.6.120.0030.04420.84
5.6.110.0030.04120.85
5.6.100.0030.07020.96
5.6.90.0060.03920.86
5.6.80.0060.04220.22
5.6.70.0070.03420.21
5.6.60.0030.04020.32
5.6.50.0030.03820.26
5.6.40.0030.04120.23
5.6.30.0040.03920.37
5.6.20.0130.07020.20
5.6.10.0000.04820.33
5.6.00.0030.04020.28
5.5.380.0100.07818.73
5.5.370.0100.04318.73
5.5.360.0030.06818.73
5.5.350.0000.04318.73
5.5.340.0030.04818.73
5.5.330.0030.03918.73
5.5.320.0070.04318.73
5.5.310.0030.04018.73
5.5.300.0000.05518.73
5.5.290.0060.04818.73
5.5.280.0000.04418.73
5.5.270.0030.04118.73
5.5.260.0060.06518.73
5.5.250.0030.05318.73
5.5.240.0000.04518.73
5.5.230.0030.04118.73
5.5.220.0060.03518.73
5.5.210.0030.04218.73
5.5.200.0100.03318.73
5.5.190.0030.04018.73
5.5.180.0070.06218.73
5.5.160.0030.04718.73
5.5.150.0000.04018.73
5.5.140.0000.04518.73
5.5.130.0070.03618.73
5.5.120.0100.07618.73
5.5.110.0070.03818.73
5.5.100.0190.03918.73
5.5.90.0030.03818.73
5.5.80.0030.04818.73
5.5.70.0030.04118.73
5.5.60.0060.03418.73
5.5.50.0030.04018.73
5.5.40.0000.04018.73
5.5.30.0000.04018.73
5.5.20.0070.03418.73
5.5.10.0100.04318.73
5.5.00.0000.04018.73
5.4.450.0030.04019.46
5.4.440.0030.04119.25
5.4.430.0030.03719.21
5.4.420.0030.05819.21
5.4.410.0030.07719.40
5.4.400.0070.04719.04
5.4.390.0070.03619.23
5.4.380.0070.03319.23
5.4.370.0030.04019.16
5.4.360.0030.03819.14
5.4.350.0130.06719.21
5.4.340.0070.07319.24
5.4.320.0030.04019.05
5.4.310.0000.05019.07
5.4.300.0030.07819.21
5.4.290.0130.02718.98
5.4.280.0030.05018.98
5.4.270.0030.04919.11
5.4.260.0200.03019.16
5.4.250.0030.03819.16
5.4.240.0100.03218.98
5.4.230.0030.04719.16
5.4.220.0000.04119.20
5.4.210.0000.04118.97
5.4.200.0000.04119.10
5.4.190.0000.04219.11
5.4.180.0070.03518.93
5.4.170.0030.03819.03
5.4.160.0030.03719.04
5.4.150.0030.04019.06
5.4.140.0030.03918.73
5.4.130.0030.03418.73
5.4.120.0030.03318.73
5.4.110.0000.04318.73
5.4.100.0000.03918.73
5.4.90.0070.03018.73
5.4.80.0030.05518.73
5.4.70.0070.03618.73
5.4.60.0030.03318.73
5.4.50.0070.04818.73
5.4.40.0000.04118.73
5.4.30.0030.03318.73
5.4.20.0130.04818.73
5.4.10.0030.03818.73
5.4.00.0000.04018.73
5.3.290.0000.04018.73
5.3.280.0030.03618.73
5.3.270.0000.04118.73
5.3.260.0060.04518.73
5.3.250.0000.04118.73
5.3.240.0000.04118.73
5.3.230.0130.03918.73
5.3.220.0000.04018.73
5.3.210.0000.04518.73
5.3.200.0000.04018.73
5.3.190.0070.07618.73
5.3.180.0060.03518.73
5.3.170.0060.03918.73
5.3.160.0100.02918.73
5.3.150.0000.07018.73
5.3.140.0000.04018.73
5.3.130.0030.07318.73
5.3.120.0100.07818.73
5.3.110.0000.04218.73
5.3.100.0060.03518.73
5.3.90.0070.03318.73
5.3.80.0030.03618.73
5.3.70.0030.03418.73
5.3.60.0100.03018.73
5.3.50.0030.03418.73
5.3.40.0030.03618.73
5.3.30.0000.03718.73
5.3.20.0070.05218.73
5.3.10.0100.04618.73
5.3.00.0000.03718.73
5.2.170.0030.02718.73
5.2.160.0000.03318.73
5.2.150.0000.03218.73
5.2.140.0000.04018.73
5.2.130.0030.03518.73
5.2.120.0000.04318.73
5.2.110.0070.04318.73
5.2.100.0000.03018.73
5.2.90.0060.02518.73
5.2.80.0060.02918.73
5.2.70.0060.02818.73
5.2.60.0030.05818.73
5.2.50.0070.05718.73
5.2.40.0030.03018.73
5.2.30.0030.06618.73
5.2.20.0030.03518.73
5.2.10.0000.03618.73
5.2.00.0030.02818.73
5.1.60.0000.03218.73
5.1.50.0000.02918.73
5.1.40.0060.01918.73
5.1.30.0000.02918.73
5.1.20.0030.02518.73
5.1.10.0000.02718.73
5.1.00.0000.03018.73
5.0.50.0000.03018.73
5.0.40.0000.02218.73
5.0.30.0000.04518.73
5.0.20.0030.02018.73
5.0.10.0000.02318.73
5.0.00.0130.03418.73
4.4.90.0100.02618.73
4.4.80.0000.03118.73
4.4.70.0000.03618.73
4.4.60.0060.01818.73
4.4.50.0030.02718.73
4.4.40.0030.02518.73
4.4.30.0030.01418.73
4.4.20.0030.01318.73
4.4.10.0000.03418.73
4.4.00.0000.02718.73
4.3.110.0030.02818.73
4.3.100.0030.02218.73
4.3.90.0000.01818.73
4.3.80.0000.02518.73
4.3.70.0030.01318.73
4.3.60.0000.01718.73
4.3.50.0120.01518.73
4.3.40.0000.02618.73
4.3.30.0000.01718.73
4.3.20.0040.01418.73
4.3.10.0030.01318.73
4.3.00.0000.02318.73

preferences:
45.54 ms | 401 KiB | 5 Q