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:1') . "\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.0100.01018.45
8.3.50.0080.01021.27
8.3.40.0150.00019.14
8.3.30.0080.00620.34
8.3.20.0060.00318.94
8.3.10.0050.00321.27
8.3.00.0000.00819.68
8.2.180.0140.00718.66
8.2.170.0120.00922.96
8.2.160.0120.00622.21
8.2.150.0100.00624.18
8.2.140.0060.00324.66
8.2.130.0060.00326.16
8.2.120.0080.00419.34
8.2.110.0100.00020.50
8.2.100.0100.00318.09
8.2.90.0040.00419.48
8.2.80.0080.00019.57
8.2.70.0060.00318.00
8.2.60.0000.00818.15
8.2.50.0000.00818.07
8.2.40.0040.00419.93
8.2.30.0040.00419.59
8.2.20.0000.00817.93
8.2.10.0060.00317.88
8.2.00.0040.00417.94
8.1.280.0070.00725.92
8.1.270.0040.00423.99
8.1.260.0120.00626.35
8.1.250.0100.01028.09
8.1.240.0030.00722.45
8.1.230.0060.00620.93
8.1.220.0080.00018.77
8.1.210.0050.00319.15
8.1.200.0030.00717.61
8.1.190.0000.00817.66
8.1.180.0040.00418.10
8.1.170.0000.00818.78
8.1.160.0000.00819.03
8.1.150.0040.00418.89
8.1.140.0030.00617.70
8.1.130.0000.00717.93
8.1.120.0030.00517.57
8.1.110.0080.00017.57
8.1.100.0000.00917.56
8.1.90.0020.00517.63
8.1.80.0040.00417.59
8.1.70.0070.00017.56
8.1.60.0080.00017.75
8.1.50.0000.00817.61
8.1.40.0050.00317.74
8.1.30.0000.00817.75
8.1.20.0040.00417.83
8.1.10.0000.00817.72
8.1.00.0040.00717.73
8.0.300.0040.00419.90
8.0.290.0080.00017.05
8.0.280.0000.00718.59
8.0.270.0040.00417.38
8.0.260.0000.00716.90
8.0.250.0040.00417.18
8.0.240.0040.00417.20
8.0.230.0000.00717.18
8.0.220.0030.00317.14
8.0.210.0040.00417.09
8.0.200.0030.00317.12
8.0.190.0040.00417.21
8.0.180.0050.00317.16
8.0.170.0000.00716.96
8.0.160.0030.00617.20
8.0.150.0040.00416.93
8.0.140.0040.00417.08
8.0.130.0060.00013.57
8.0.120.0000.00817.09
8.0.110.0090.00016.95
8.0.100.0040.00417.17
8.0.90.0050.00317.05
8.0.80.0150.00017.09
8.0.70.0040.00417.14
8.0.60.0040.00416.97
8.0.50.0030.00617.09
8.0.30.0110.00817.44
8.0.20.0130.01017.41
8.0.10.0040.00417.09
8.0.00.0070.01217.04
7.4.330.0050.00016.73
7.4.320.0000.00816.88
7.4.300.0000.00616.75
7.4.290.0050.00316.77
7.4.280.0030.00316.76
7.4.270.0040.00416.82
7.4.260.0000.00613.53
7.4.250.0080.00016.84
7.4.240.0000.00716.80
7.4.230.0050.00216.78
7.4.220.0070.01116.69
7.4.210.0080.00716.82
7.4.200.0000.00716.95
7.4.190.0000.00716.73
7.4.160.0070.01017.04
7.4.150.0030.01717.40
7.4.140.0130.00517.86
7.4.130.0100.00816.79
7.4.120.0060.01216.69
7.4.110.0090.00916.82
7.4.100.0120.00816.86
7.4.90.0150.00916.65
7.4.80.0090.01619.39
7.4.70.0100.00716.93
7.4.60.0090.00916.78
7.4.50.0030.00316.69
7.4.40.0000.01122.77
7.4.30.0000.02216.73
7.4.10.0060.00615.03
7.4.00.0040.01315.24
7.3.330.0030.00313.49
7.3.320.0000.00513.48
7.3.310.0000.00816.45
7.3.300.0070.00016.43
7.3.290.0100.01016.48
7.3.280.0050.01116.57
7.3.270.0070.01117.40
7.3.260.0170.00818.24
7.3.250.0080.01216.68
7.3.240.0070.01016.98
7.3.230.0140.00616.70
7.3.210.0190.00716.89
7.3.200.0060.01619.39
7.3.190.0050.01316.80
7.3.180.0100.00716.65
7.3.170.0040.01116.80
7.3.160.0080.00816.43
7.3.130.0100.01014.77
7.3.120.0080.00815.00
7.3.110.0120.00815.20
7.3.100.0080.00814.98
7.3.90.0050.01114.91
7.3.80.0050.00615.06
7.3.70.0050.01115.01
7.3.60.0090.00715.09
7.3.50.0050.00615.12
7.3.40.0050.00815.12
7.3.30.0090.00514.89
7.3.20.0080.00416.93
7.3.10.0020.01116.78
7.3.00.0070.00816.88
7.2.330.0090.00916.80
7.2.320.0140.00416.90
7.2.310.0110.00716.88
7.2.300.0030.01316.82
7.2.290.0030.01316.88
7.2.260.0070.01415.38
7.2.250.0130.00715.25
7.2.240.0050.01215.10
7.2.230.0090.00315.35
7.2.220.0050.01115.26
7.2.210.0060.00615.34
7.2.200.0080.00815.36
7.2.190.0090.00615.34
7.2.180.0090.00515.44
7.2.170.0060.00815.07
7.2.160.0070.01015.32
7.2.150.0040.01416.98
7.2.140.0120.00616.86
7.2.130.0060.01017.02
7.2.120.0100.00717.08
7.2.110.0120.00717.05
7.2.100.0050.01217.09
7.2.90.0080.01017.17
7.2.80.0060.01517.14
7.2.70.0050.01017.16
7.2.60.0070.00817.17
7.2.50.0150.00517.20
7.2.40.0070.01117.15
7.2.30.0090.00817.18
7.2.20.0100.00816.98
7.2.10.0070.00817.00
7.2.00.0080.00918.02
7.1.330.0040.00915.95
7.1.320.0050.01016.05
7.1.310.0020.01115.96
7.1.300.0090.00515.88
7.1.290.0090.00516.14
7.1.280.0030.01015.89
7.1.270.0030.00915.84
7.1.260.0070.00915.91
7.1.250.0070.01015.84
7.1.240.0090.00416.18
7.1.230.0060.00816.16
7.1.220.0040.01515.64
7.1.210.0110.00415.95
7.1.200.0060.00916.05
7.1.190.0000.00916.03
7.1.180.0000.01515.98
7.1.170.0060.00915.91
7.1.160.0030.01016.09
7.1.150.0060.00916.15
7.1.140.0030.00916.00
7.1.130.0100.00315.95
7.1.120.0000.01715.89
7.1.110.0060.01015.96
7.1.100.0070.00717.28
7.1.90.0060.00916.20
7.1.80.0070.00716.01
7.1.70.0030.00916.67
7.1.60.0090.00616.73
7.1.50.0090.00916.58
7.1.40.0050.00716.56
7.1.30.0040.00916.46
7.1.20.0050.01016.38
7.1.10.0050.00916.43
7.1.00.0060.00616.55
7.0.330.0030.01015.64
7.0.320.0000.00815.72
7.0.310.0000.01315.57
7.0.300.0000.01315.58
7.0.290.0060.00315.63
7.0.280.0040.00815.58
7.0.270.0070.00715.45
7.0.260.0090.00615.53
7.0.250.0100.00715.62
7.0.240.0030.00915.51
7.0.230.0130.00015.70
7.0.220.0120.00615.79
7.0.210.0000.01415.76
7.0.200.0060.00616.28
7.0.190.0040.00716.34
7.0.180.0040.00816.23
7.0.170.0040.00616.26
7.0.160.0070.00816.31
7.0.150.0020.00816.34
7.0.140.0060.00516.40
7.0.130.0050.00716.17
7.0.120.0030.00816.23
7.0.110.0060.00516.33
7.0.100.0010.00816.38
7.0.90.0040.00516.24
7.0.80.0060.00616.25
7.0.70.0010.00716.35
7.0.60.0030.00616.37
7.0.50.0030.00816.37
7.0.40.0030.00815.37
7.0.30.0050.00515.37
7.0.20.0010.01015.34
7.0.10.0000.00915.42
7.0.00.0050.00415.35
5.6.400.0080.01114.74
5.6.390.0060.00614.63
5.6.380.0040.01114.51
5.6.370.0040.00814.46
5.6.360.0000.01414.13
5.6.350.0000.00914.73
5.6.340.0090.00614.60
5.6.330.0090.00614.48
5.6.320.0030.01414.63
5.6.310.0120.00314.67
5.6.300.0040.02717.44
5.6.290.0020.03417.57
5.6.280.0030.02817.71
5.6.270.0060.02517.77
5.6.260.0030.02917.89
5.6.250.0060.02417.70
5.6.240.0020.02717.74
5.6.230.0060.02317.80
5.6.220.0020.02617.71
5.6.210.0020.02817.50
5.6.200.0090.02517.85
5.6.190.0040.02717.74
5.6.180.0050.02917.71
5.6.170.0030.02717.64
5.6.160.0070.02017.79
5.6.150.0060.02817.79
5.6.140.0050.02717.76
5.6.130.0070.03317.70
5.6.120.0140.01917.81
5.6.110.0020.02917.76
5.6.100.0000.03017.66
5.6.90.0020.04917.83
5.6.80.0030.02717.45
5.6.70.0080.02017.29
5.6.60.0050.02317.52
5.6.50.0030.02517.31
5.6.40.0060.02017.18
5.6.30.0070.03117.19
5.6.20.0060.02317.30
5.6.10.0060.02117.28
5.6.00.0060.02517.36
5.5.380.0020.02916.03
5.5.370.0030.02216.06
5.5.360.0030.02515.96
5.5.350.0020.02715.97
5.5.340.0030.02316.32
5.5.330.0020.02416.37
5.5.320.0030.02616.12
5.5.310.0020.02516.27
5.5.300.0060.03116.43
5.5.290.0070.02516.29
5.5.280.0030.02616.11
5.5.270.0100.02516.27
5.5.260.0090.03716.25
5.5.250.0030.02516.24
5.5.240.0050.02016.02
5.5.230.0030.02315.92
5.5.220.0070.02115.98
5.5.210.0030.02315.91
5.5.200.0030.02715.98
5.5.190.0010.02615.85
5.5.180.0050.02015.82
5.5.170.0000.00814.46
5.5.160.0040.02216.04
5.5.150.0030.02415.98
5.5.140.0140.02515.84
5.5.130.0030.02316.02
5.5.120.0060.02115.94
5.5.110.0020.04115.84
5.5.100.0020.02515.81
5.5.90.0020.02315.52
5.5.80.0070.02215.79
5.5.70.0030.02515.87
5.5.60.0070.02615.84
5.5.50.0030.02515.73
5.5.40.0020.02615.94
5.5.30.0070.01915.85
5.5.20.0070.02615.92
5.5.10.0030.02815.94
5.5.00.0050.02015.76
5.4.450.0020.02615.20
5.4.440.0030.02915.47
5.4.430.0060.02115.34
5.4.420.0030.03615.32
5.4.410.0000.02615.12
5.4.400.0020.02315.23
5.4.390.0210.02815.10
5.4.380.0050.02215.06
5.4.370.0050.01815.19
5.4.360.0050.02415.16
5.4.350.0030.02215.06
5.4.340.0020.02415.27
5.4.330.0060.00311.26
5.4.320.0000.02915.26
5.4.310.0030.02014.97
5.4.300.0030.02215.35
5.4.290.0050.01815.26
5.4.280.0020.02615.20
5.4.270.0040.02215.16
5.4.260.0020.02415.22
5.4.250.0030.02515.02
5.4.240.0020.02215.25
5.4.230.0030.02415.27
5.4.220.0050.03515.14
5.4.210.0050.02015.13
5.4.200.0040.02414.95
5.4.190.0050.02415.21
5.4.180.0090.02215.24
5.4.170.0030.02415.10
5.4.160.0030.02215.11
5.4.150.0090.01615.14
5.4.140.0040.02014.27
5.4.130.0030.02214.10
5.4.120.0060.01814.13
5.4.110.0070.02314.13
5.4.100.0030.02114.12
5.4.90.0030.02213.98
5.4.80.0020.02414.03
5.4.70.0060.01814.19
5.4.60.0060.01914.16
5.4.50.0050.02214.15
5.4.40.0050.01714.10
5.4.30.0030.02114.22
5.4.20.0020.02314.18
5.4.10.0040.01914.21
5.4.00.0030.02214.01
5.3.290.0050.02213.93
5.3.280.0110.02113.77
5.3.270.0030.02213.80
5.3.260.0050.02813.86
5.3.250.0030.02013.93
5.3.240.0020.02213.71
5.3.230.0030.02413.92
5.3.220.0000.02313.85
5.3.210.0020.02213.83
5.3.200.0000.02413.89
5.3.190.0020.02513.71
5.3.180.0000.02213.91
5.3.170.0000.02713.83
5.3.160.0020.02513.90
5.3.150.0030.02313.77
5.3.140.0050.02013.77
5.3.130.0060.02113.86
5.3.120.0050.02213.88
5.3.110.0000.02913.87
5.3.100.0050.02013.73
5.3.90.0030.01813.90
5.3.80.0060.02413.81
5.3.70.0100.01913.88
5.3.60.0090.01513.82
5.3.50.0000.02413.84
5.3.40.0020.02213.79
5.3.30.0040.01813.85
5.3.20.0050.01613.83
5.3.10.0050.01713.68
5.3.00.0020.02113.73
5.2.170.0030.03117.02
5.2.160.0000.03217.02
5.2.150.0000.03217.02
5.2.140.0000.03617.02
5.2.130.0040.02617.02
5.2.120.0030.02617.02
5.2.110.0040.02517.02
5.2.100.0000.03017.02
5.2.90.0030.02617.02
5.2.80.0030.02717.02
5.2.70.0030.03317.02
5.2.60.0000.03317.02
5.2.50.0030.03017.02
5.2.40.0000.03117.02
5.2.30.0060.02417.02
5.2.20.0030.02817.02
5.2.10.0030.02817.02
5.2.00.0000.03017.02
5.1.60.0000.02617.02
5.1.50.0000.02517.02
5.1.40.0000.03317.02
5.1.30.0030.02517.02
5.1.20.0000.02917.02
5.1.10.0030.02317.02
5.1.00.0000.02717.02
5.0.50.0000.02617.02
5.0.40.0000.02317.02
5.0.30.0030.03017.02
5.0.20.0070.01717.02
5.0.10.0140.01417.02
5.0.00.0030.03617.02
4.4.90.0060.01017.02
4.4.80.0000.01717.02
4.4.70.0000.01617.02
4.4.60.0000.01617.02
4.4.50.0030.01317.02
4.4.40.0060.01917.02
4.4.30.0030.01317.02
4.4.20.0000.01617.02
4.4.10.0030.01517.02
4.4.00.0000.02817.02
4.3.110.0030.01317.02
4.3.100.0000.01817.02
4.3.90.0000.01917.02
4.3.80.0000.02617.02
4.3.70.0000.01817.02
4.3.60.0000.01617.02
4.3.50.0000.01717.02
4.3.40.0000.02517.02
4.3.30.0060.01117.02
4.3.20.0000.01917.02
4.3.10.0000.01717.02
4.3.00.0000.01717.02

preferences:
46.04 ms | 400 KiB | 5 Q