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] === '') { 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.0040.01118.43
8.3.50.0170.01021.34
8.3.40.0040.01119.09
8.3.30.0070.00720.34
8.3.20.0080.00018.98
8.3.10.0040.00421.22
8.3.00.0040.00419.79
8.2.180.0110.00416.88
8.2.170.0130.00322.96
8.2.160.0080.00620.54
8.2.150.0060.00324.18
8.2.140.0000.00824.66
8.2.130.0030.00526.16
8.2.120.0090.00019.22
8.2.110.0060.00320.44
8.2.100.0060.00617.97
8.2.90.0000.00817.88
8.2.80.0040.00420.55
8.2.70.0000.00918.16
8.2.60.0000.00818.34
8.2.50.0080.00018.10
8.2.40.0040.00420.55
8.2.30.0040.00421.35
8.2.20.0000.00917.82
8.2.10.0040.00418.01
8.2.00.0090.00017.91
8.1.280.0110.00325.92
8.1.270.0070.00023.99
8.1.260.0080.00826.35
8.1.250.0030.00528.09
8.1.240.0060.00322.64
8.1.230.0110.00021.06
8.1.220.0050.00317.89
8.1.210.0050.00318.77
8.1.200.0030.01017.60
8.1.190.0000.00817.60
8.1.180.0040.00418.10
8.1.170.0000.00918.68
8.1.160.0040.00418.96
8.1.150.0000.00818.77
8.1.140.0020.00517.64
8.1.130.0030.00317.91
8.1.120.0040.00417.66
8.1.110.0040.00417.54
8.1.100.0040.00417.65
8.1.90.0070.00017.64
8.1.80.0040.00417.56
8.1.70.0030.00317.57
8.1.60.0090.00017.80
8.1.50.0060.00317.60
8.1.40.0040.00417.67
8.1.30.0080.00017.87
8.1.20.0000.00817.90
8.1.10.0040.00417.64
8.1.00.0040.00717.75
8.0.300.0000.00920.17
8.0.290.0000.00716.88
8.0.280.0030.00318.65
8.0.270.0000.00717.36
8.0.260.0000.00716.93
8.0.250.0000.00717.20
8.0.240.0040.00416.99
8.0.230.0040.00417.14
8.0.220.0050.00217.03
8.0.210.0000.00717.10
8.0.200.0000.00717.02
8.0.190.0030.00517.16
8.0.180.0040.00417.09
8.0.170.0000.00816.90
8.0.160.0040.00717.06
8.0.150.0000.00717.05
8.0.140.0040.00416.93
8.0.130.0030.00313.54
8.0.120.0040.00417.07
8.0.110.0000.00717.00
8.0.100.0040.00417.09
8.0.90.0060.00317.01
8.0.80.0090.01317.05
8.0.70.0040.00417.14
8.0.60.0040.00416.95
8.0.50.0050.00317.12
8.0.30.0030.01717.37
8.0.20.0140.00817.56
8.0.10.0030.00517.33
8.0.00.0130.00617.10
7.4.330.0000.00515.11
7.4.320.0030.00316.75
7.4.300.0030.00616.86
7.4.290.0000.00716.78
7.4.280.0040.00416.78
7.4.270.0070.00016.73
7.4.260.0000.00513.54
7.4.250.0040.00416.77
7.4.240.0000.00716.92
7.4.230.0040.00416.68
7.4.220.0070.01116.74
7.4.210.0070.00916.84
7.4.200.0040.00416.87
7.4.190.0030.00416.84
7.4.160.0030.01216.83
7.4.150.0130.00717.40
7.4.140.0080.01017.86
7.4.130.0130.00416.69
7.4.120.0070.01016.76
7.4.110.0110.00716.80
7.4.100.0130.01016.84
7.4.90.0120.00616.85
7.4.80.0150.00319.39
7.4.70.0120.00616.71
7.4.60.0120.00916.89
7.4.50.0030.00316.57
7.4.40.0070.00522.77
7.4.30.0090.01616.68
7.4.00.0090.00715.18
7.3.330.0000.00513.52
7.3.320.0030.00313.34
7.3.310.0070.00016.51
7.3.300.0000.00616.54
7.3.290.0070.00716.48
7.3.280.0090.00916.55
7.3.270.0150.00317.40
7.3.260.0060.01218.24
7.3.250.0150.00316.68
7.3.240.0080.00916.50
7.3.230.0090.01316.55
7.3.210.0160.00616.76
7.3.200.0070.01519.39
7.3.190.0060.01216.68
7.3.180.0100.00616.70
7.3.170.0060.00916.83
7.3.160.0090.01216.51
7.3.120.0060.01315.10
7.3.110.0100.00815.11
7.3.100.0080.00815.21
7.3.90.0080.00515.07
7.3.80.0050.01014.94
7.3.70.0080.00515.08
7.3.60.0070.00815.05
7.3.50.0080.00715.06
7.3.40.0080.00515.13
7.3.30.0070.00715.06
7.3.20.0040.01116.93
7.3.10.0060.01216.96
7.3.00.0040.01116.70
7.2.330.0100.00717.01
7.2.320.0120.00616.92
7.2.310.0080.01116.98
7.2.300.0070.01016.76
7.2.290.0110.00816.75
7.2.250.0060.01015.36
7.2.240.0110.00815.25
7.2.230.0090.00615.29
7.2.220.0040.00915.31
7.2.210.0050.00915.22
7.2.200.0060.00715.40
7.2.190.0020.01415.42
7.2.180.0100.00315.26
7.2.170.0050.00815.30
7.2.160.0070.01015.09
7.2.150.0090.00917.27
7.2.140.0070.01317.05
7.2.130.0110.00417.13
7.2.120.0080.00616.98
7.2.110.0060.00816.90
7.2.100.0070.00716.97
7.2.90.0090.00517.04
7.2.80.0080.00916.85
7.2.70.0070.00717.22
7.2.60.0090.00617.13
7.2.50.0060.00817.20
7.2.40.0050.00916.96
7.2.30.0070.00517.27
7.2.20.0060.00717.11
7.2.10.0070.00217.13
7.2.00.0050.00917.90
7.1.330.0070.00716.01
7.1.320.0060.00615.95
7.1.310.0070.00915.96
7.1.300.0060.00616.10
7.1.290.0080.00615.96
7.1.280.0060.00615.87
7.1.270.0030.00915.94
7.1.260.0050.00815.84
7.1.250.0100.00315.86
7.1.240.0070.00715.80
7.1.230.0030.00616.08
7.1.220.0090.00615.91
7.1.210.0000.01115.99
7.1.200.0100.00316.01
7.1.190.0000.01416.06
7.1.180.0000.00915.77
7.1.170.0030.00715.88
7.1.160.0000.00916.11
7.1.150.0000.01616.05
7.1.140.0060.00915.75
7.1.130.0030.00916.16
7.1.120.0030.01215.79
7.1.110.0040.00416.01
7.1.100.0060.00617.30
7.1.90.0060.00915.64
7.1.80.0070.00715.70
7.1.70.0060.00416.74
7.1.60.0020.01116.79
7.1.50.0030.00916.54
7.1.40.0010.00816.28
7.1.30.0080.00616.49
7.1.20.0060.00716.40
7.1.10.0060.00616.35
7.1.00.0030.00616.50
7.0.320.0030.01015.41
7.0.310.0040.00715.65
7.0.300.0130.00015.63
7.0.290.0060.00615.80
7.0.280.0030.01015.64
7.0.270.0060.00915.62
7.0.260.0070.00715.34
7.0.250.0150.00015.68
7.0.240.0030.01015.80
7.0.230.0090.00615.52
7.0.220.0040.00815.68
7.0.210.0000.01115.82
7.0.200.0030.00816.29
7.0.190.0020.00916.36
7.0.180.0060.00516.10
7.0.170.0050.00515.94
7.0.160.0020.01016.07
7.0.150.0020.00816.15
7.0.140.0040.00716.14
7.0.130.0040.00816.26
7.0.120.0050.00316.07
7.0.110.0060.00516.10
7.0.100.0000.01216.09
7.0.90.0010.00616.18
7.0.80.0040.00616.10
7.0.70.0030.00616.20
7.0.60.0010.00615.97
7.0.50.0040.00716.08
7.0.40.0060.00315.04
7.0.30.0050.00715.03
7.0.20.0020.00815.09
7.0.10.0030.00715.01
7.0.00.0030.00915.08
5.6.380.0030.01014.76
5.6.370.0060.00614.17
5.6.360.0040.01114.57
5.6.350.0060.00614.86
5.6.340.0090.00614.79
5.6.330.0000.01214.86
5.6.320.0090.00014.46
5.6.310.0030.00914.55
5.6.300.0000.02817.79
5.6.290.0060.02317.52
5.6.280.0050.02517.73
5.6.270.0070.02217.89
5.6.260.0030.02917.74
5.6.250.0050.02317.81
5.6.240.0030.02317.65
5.6.230.0080.02117.81
5.6.220.0070.02317.62
5.6.210.0050.03717.47
5.6.200.0050.02317.69
5.6.190.0030.02517.79
5.6.180.0040.02717.81
5.6.170.0120.02317.60
5.6.160.0050.02417.81
5.6.150.0020.02817.55
5.6.140.0050.02517.68
5.6.130.0020.02717.61
5.6.120.0020.03017.68
5.6.110.0000.03017.82
5.6.100.0050.02317.72
5.6.90.0060.02117.69
5.6.80.0030.02717.28
5.6.70.0050.02117.42
5.6.60.0050.02417.19
5.6.50.0040.02517.21
5.6.40.0050.02317.28
5.6.30.0050.02317.52
5.6.20.0080.02317.28
5.6.10.0050.03317.31
5.6.00.0020.02417.30
5.5.380.0050.02114.37
5.5.370.0030.02414.38
5.5.360.0030.02114.61
5.5.350.0050.02114.33
5.5.340.0070.02714.74
5.5.330.0050.02414.85
5.5.320.0030.02514.59
5.5.310.0030.02614.83
5.5.300.0050.02314.87
5.5.290.0030.02314.72
5.5.280.0050.02214.82
5.5.270.0030.02614.75
5.5.260.0030.02514.84
5.5.250.0020.02514.49
5.5.240.0030.02114.46
5.5.230.0080.02014.42
5.5.220.0100.02014.38
5.5.210.0050.02514.35
5.5.200.0010.02414.45
5.5.190.0030.02514.42
5.5.180.0000.02814.44
5.5.170.0030.01014.37
5.5.160.0050.03314.39
5.5.150.0020.03314.44
5.5.140.0000.02614.44
5.5.130.0030.02414.34
5.5.120.0030.02414.42
5.5.110.0020.03214.42
5.5.100.0050.02214.12
5.5.90.0050.02214.22
5.5.80.0050.02214.41
5.5.70.0050.02214.41
5.5.60.0030.02214.32
5.5.50.0030.02214.28
5.5.40.0020.02714.09
5.5.30.0070.01814.31
5.5.20.0020.02514.22
5.5.10.0050.02713.92
5.5.00.0050.02114.24
5.4.450.0030.02315.35
5.4.440.0020.02515.44
5.4.430.0190.01415.44
5.4.420.0020.02715.21
5.4.410.0030.02215.38
5.4.400.0050.02115.14
5.4.390.0030.02314.95
5.4.380.0040.02215.14
5.4.370.0050.02115.02
5.4.360.0020.02315.30
5.4.350.0030.02415.12
5.4.340.0060.01815.15
5.4.330.0060.00611.24
5.4.320.0040.03415.07
5.4.310.0050.02215.11
5.4.300.0050.02115.39
5.4.290.0050.02015.04
5.4.280.0070.02015.27
5.4.270.0060.04015.08
5.4.260.0030.02415.22
5.4.250.0050.02015.04
5.4.240.0020.02415.02
5.4.230.0030.03415.15
5.4.220.0060.03115.15
5.4.210.0060.02115.24
5.4.200.0090.01814.97
5.4.190.0030.02515.18
5.4.180.0030.02215.19
5.4.170.0010.02414.98
5.4.160.0040.02315.35
5.4.150.0030.02115.11
5.4.140.0050.02113.84
5.4.130.0030.02113.98
5.4.120.0050.01814.01
5.4.110.0030.02113.94
5.4.100.0060.01914.15
5.4.90.0020.02213.95
5.4.80.0050.02413.91
5.4.70.0030.02213.90
5.4.60.0030.02113.80
5.4.50.0050.02314.04
5.4.40.0020.02613.91
5.4.30.0050.01813.91
5.4.20.0060.01813.85
5.4.10.0050.02013.87
5.4.00.0030.02113.75
5.3.290.0030.02213.63
5.3.280.0020.02813.43
5.3.270.0050.02813.67
5.3.260.0040.02313.64
5.3.250.0030.02413.62
5.3.240.0050.01813.57
5.3.230.0050.02013.60
5.3.220.0020.02413.53
5.3.210.0020.02413.46
5.3.200.0020.02813.57
5.3.190.0020.02313.64
5.3.180.0020.02513.53
5.3.170.0060.02013.59
5.3.160.0060.01813.63
5.3.150.0020.02513.63
5.3.140.0000.02213.67
5.3.130.0060.02613.58
5.3.120.0030.02213.56
5.3.110.0050.02213.60
5.3.100.0050.01913.43
5.3.90.0000.02513.67
5.3.80.0070.01713.43
5.3.70.0050.01913.57
5.3.60.0080.02913.42
5.3.50.0020.02213.56
5.3.40.0060.01713.47
5.3.30.0020.02213.42
5.3.20.0030.02313.54
5.3.10.0020.02413.53
5.3.00.0040.01813.35
5.2.170.0020.02913.15
5.2.160.0020.02113.15
5.2.150.0040.01713.15
5.2.140.0050.02213.15
5.2.130.0080.01313.15
5.2.120.0020.02013.15
5.2.110.0070.01313.15
5.2.100.0080.03113.15
5.2.90.0050.01713.15
5.2.80.0050.02313.15
5.2.70.0010.02013.15
5.2.60.0030.01913.15
5.2.50.0010.01813.15
5.2.40.0020.01913.15
5.2.30.0070.01513.15
5.2.20.0030.01713.15
5.2.10.0070.01313.15
5.2.00.0050.01213.15
5.1.60.0040.01713.15
5.1.50.0040.02113.15
5.1.40.0050.01513.15
5.1.30.0030.01413.15
5.1.20.0010.01713.15
5.1.10.0020.01713.15
5.1.00.0020.01713.15
5.0.50.0030.01113.15
5.0.40.0040.01113.15
5.0.30.0020.01713.15
5.0.20.0040.01013.15
5.0.10.0010.01413.15
5.0.00.0040.01713.15
4.4.90.0050.00813.15
4.4.80.0040.00713.15
4.4.70.0020.01013.15
4.4.60.0050.00713.15
4.4.50.0020.00913.15
4.4.40.0000.01813.15
4.4.30.0020.01513.15
4.4.20.0030.01113.15
4.4.10.0010.01013.15
4.4.00.0040.01413.15
4.3.110.0030.01113.15
4.3.100.0030.00813.15
4.3.90.0050.00913.15
4.3.80.0020.01313.15
4.3.70.0020.00913.15
4.3.60.0020.00913.15
4.3.50.0030.00813.15
4.3.40.0030.01313.15
4.3.30.0010.01113.15
4.3.20.0050.00713.15
4.3.10.0020.01113.15
4.3.00.0000.01113.15

preferences:
52.45 ms | 401 KiB | 5 Q