3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Normalise a path, resolving empty, . and .. components, optionally against another path * * @param string $path * @param string $target * @return string */ function resolve_path($path, $relativeBase = null) { // Find separator in use and determine whether output path should be absolute $separator = strpos($path, '\\') !== false || strpos($relativeBase, '\\') !== false ? '\\' : '/'; $isAbsolute = (!isset($relativeBase) && ($path[0] === '/' || $path[0] === '\\')) || (isset($relativeBase) && ($relativeBase[0] === '/' || $relativeBase[0] === '\\')); // Create the base output array $target = $relativeBase !== null ? preg_split('#[\\\\/]+#', $relativeBase, -1, PREG_SPLIT_NO_EMPTY) : []; // Strip empty components and resolve . and .. foreach (preg_split('#[\\\\/]+#', $path, -1, PREG_SPLIT_NO_EMPTY) as $component) { switch ($component) { case '.': // current directory - do nothing break; case '..': // up a level array_pop($target); break; default: $target[] = $component; break; } } // Add a trailing empty element if path refers to a directory $lastChar = $path[strlen($path) - 1]; if ($lastChar === '/' || $lastChar === '\\') { $target[] = ''; } // Add a leading slash if path is absolute if ($isAbsolute) { if ($target) { array_unshift($target, ''); } else { $target = ['', '']; } } return implode($separator, $target); } $tests = [ '/foo/bar/./../baz' => null, '/foo/bar/./../../baz/..' => null, '/foo/bar/' => '/baz/qux', '../..' => '/foo/bar/baz/qux' ]; foreach ($tests as $path => $base) { $result = resolve_path($path, $base); echo " Path: $path Base: $base Result: $result "; }

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.00019.07
8.3.30.0110.00319.20
8.3.20.0000.00720.33
8.3.10.0040.00421.92
8.3.00.0030.00522.51
8.2.170.0150.00022.96
8.2.160.0000.01419.16
8.2.150.0040.00424.18
8.2.140.0090.00024.66
8.2.130.0040.00426.16
8.2.120.0030.00519.48
8.2.110.0060.00320.52
8.2.100.0000.01117.85
8.2.90.0000.00819.36
8.2.80.0060.00318.05
8.2.70.0000.00817.88
8.2.60.0080.00018.05
8.2.50.0030.00618.07
8.2.40.0030.00618.34
8.2.30.0040.00418.13
8.2.20.0060.00317.96
8.2.10.0040.00418.11
8.2.00.0060.00618.00
8.1.270.0040.00422.05
8.1.260.0050.00326.35
8.1.250.0090.00028.09
8.1.240.0090.00022.10
8.1.230.0030.00917.64
8.1.220.0050.00317.74
8.1.210.0040.00418.77
8.1.200.0030.00617.48
8.1.190.0000.00817.53
8.1.180.0040.00418.77
8.1.170.0000.00818.75
8.1.160.0000.00822.20
8.1.150.0030.00618.86
8.1.140.0030.00517.72
8.1.130.0030.00517.94
8.1.120.0070.00017.47
8.1.110.0030.00617.61
8.1.100.0070.00017.59
8.1.90.0040.00417.65
8.1.80.0070.00017.69
8.1.70.0040.00417.47
8.1.60.0080.00317.79
8.1.50.0040.00417.57
8.1.40.0030.00617.57
8.1.30.0060.00317.86
8.1.20.0040.00417.80
8.1.10.0040.00417.63
8.1.00.0000.00917.74
8.0.300.0040.00418.77
8.0.290.0000.00817.18
8.0.280.0000.00718.44
8.0.270.0030.00317.29
8.0.260.0000.00717.01
8.0.250.0000.00717.11
8.0.240.0030.00317.17
8.0.230.0050.00217.17
8.0.220.0070.00017.00
8.0.210.0030.00417.00
8.0.200.0000.00717.09
8.0.190.0050.00317.02
8.0.180.0000.00717.04
8.0.170.0080.00017.10
8.0.160.0060.00316.93
8.0.150.0040.00416.95
8.0.140.0050.00217.09
8.0.130.0060.00013.55
8.0.120.0000.00716.92
8.0.110.0070.00017.08
8.0.100.0000.00717.06
8.0.90.0050.00216.99
8.0.80.0120.00317.18
8.0.70.0040.00416.93
8.0.60.0000.00717.17
8.0.50.0040.00417.01
8.0.30.0140.00517.19
8.0.20.0070.01317.44
8.0.10.0040.00417.18
8.0.00.0150.02017.05
7.4.330.0050.00015.00
7.4.320.0000.00716.79
7.4.300.0060.00016.64
7.4.290.0050.00316.87
7.4.280.0070.00016.85
7.4.270.0030.00316.89
7.4.260.0000.00816.88
7.4.250.0000.00716.70
7.4.240.0040.00416.78
7.4.230.0030.00517.00
7.4.220.0040.01516.79
7.4.210.0050.00916.88
7.4.200.0070.00016.92
7.4.190.0000.00716.92
7.4.160.0090.00616.64
7.4.150.0110.00717.40
7.4.140.0120.00717.86
7.4.130.0090.00916.75
7.4.120.0100.00716.77
7.4.110.0100.00716.74
7.4.100.0090.00916.88
7.4.90.0150.00316.61
7.4.80.0100.01319.39
7.4.70.0160.00316.84
7.4.60.0090.00916.78
7.4.50.0030.00616.77
7.4.40.0070.01122.77
7.4.30.0090.00916.68
7.4.00.0110.00715.37
7.3.330.0000.00613.37
7.3.320.0030.00313.39
7.3.310.0030.00416.43
7.3.300.0000.00716.54
7.3.290.0030.01016.55
7.3.280.0120.00516.52
7.3.270.0030.01517.40
7.3.260.0070.01016.55
7.3.250.0120.00516.54
7.3.240.0110.00616.80
7.3.230.0080.00816.58
7.3.210.0110.00616.57
7.3.200.0030.01319.39
7.3.190.0100.01116.75
7.3.180.0080.00816.64
7.3.170.0110.00716.56
7.3.160.0090.01216.82
7.3.120.0070.00415.08
7.3.110.0040.00414.93
7.3.100.0040.00414.96
7.3.90.0070.00715.22
7.3.80.0070.00715.21
7.3.70.0000.01214.95
7.3.60.0130.00315.07
7.3.50.0030.00915.08
7.3.40.0080.00315.17
7.3.30.0070.00714.82
7.3.20.0030.01016.88
7.3.10.0090.00916.84
7.3.00.0060.00616.73
7.2.330.0070.01016.78
7.2.320.0100.01016.89
7.2.310.0090.01217.03
7.2.300.0120.00616.89
7.2.290.0090.00617.00
7.2.240.0030.01215.19
7.2.230.0030.01415.39
7.2.220.0060.00614.98
7.2.210.0060.00315.14
7.2.200.0130.00315.41
7.2.190.0110.00415.45
7.2.180.0030.01015.31
7.2.170.0090.00315.24
7.2.160.0040.01115.45
7.2.150.0030.00716.95
7.2.140.0000.01617.17
7.2.130.0060.01016.88
7.2.120.0070.00717.22
7.2.110.0110.00917.01
7.2.100.0090.00617.18
7.2.90.0160.00516.80
7.2.80.0150.00716.94
7.2.70.0120.00816.79
7.2.60.0120.00816.70
7.2.50.0060.00917.13
7.2.40.0110.00716.98
7.2.30.0090.01116.82
7.2.20.0090.00916.64
7.2.10.0090.00916.91
7.2.00.0080.00817.96
7.1.330.0040.00815.66
7.1.320.0080.00615.71
7.1.310.0070.00715.61
7.1.300.0120.00316.17
7.1.290.0040.01116.06
7.1.280.0120.00615.92
7.1.270.0100.00716.17
7.1.260.0040.01115.93
7.1.250.0060.01016.14
7.1.100.0100.00718.48
7.1.70.0090.00417.43
7.1.60.0150.00919.82
7.1.50.0030.02117.31
7.1.00.0130.07022.36
7.0.200.0030.00616.98
7.0.140.0000.07321.95
7.0.100.0030.05019.93
7.0.90.0270.08319.90
7.0.80.0130.08019.95
7.0.70.0070.05020.00
7.0.60.0100.07319.92
7.0.50.0100.04020.41
7.0.40.0100.08320.18
7.0.30.0130.07720.07
7.0.20.0100.05320.09
7.0.10.0030.08319.99
7.0.00.0100.06720.14
5.6.280.0070.07021.09
5.6.250.0170.06020.58
5.6.240.0130.07320.61
5.6.230.0100.07720.56
5.6.220.0000.08720.63
5.6.210.0030.08720.77
5.6.200.0100.07721.07
5.6.190.0070.08021.10
5.6.180.0100.08021.13
5.6.170.0070.04721.06
5.6.160.0070.07721.18
5.6.150.0130.07720.96
5.6.140.0130.07321.07
5.6.130.0100.08320.96
5.6.120.0030.05020.98
5.6.110.0100.08021.01
5.6.100.0170.06720.95
5.6.90.0030.05021.01
5.6.80.0070.04320.50
5.6.70.0100.08020.49
5.6.60.0070.04320.45
5.6.50.0030.04720.51
5.6.40.0130.07720.37
5.6.30.0230.06020.50
5.6.20.0030.04720.32
5.6.10.0070.06720.47
5.6.00.0100.06720.38
5.5.380.0170.06720.56
5.5.370.0000.05720.43
5.5.360.0100.09020.43
5.5.350.0130.07720.43
5.5.340.0100.08020.90
5.5.330.0130.07720.66
5.5.320.0100.08320.93
5.5.310.0100.06320.85
5.5.300.0070.05720.87
5.5.290.0130.04720.95
5.5.280.0130.07320.81
5.5.270.0130.07720.87
5.5.260.0130.05320.80
5.5.250.0130.04320.60
5.5.240.0100.08020.16
5.5.230.0100.07320.27
5.5.220.0100.07320.30
5.5.210.0170.07320.15
5.5.200.0070.04720.01
5.5.190.0100.04020.13
5.5.180.0130.06320.10
5.5.160.0000.06720.08
5.5.150.0030.04020.14
5.5.140.0100.03320.09
5.5.130.0030.04720.00
5.5.120.0130.03020.12
5.5.110.0030.04020.16
5.5.100.0130.03320.18
5.5.90.0070.03320.12
5.5.80.0000.05320.02
5.5.70.0030.04719.95
5.5.60.0100.03319.97
5.5.50.0100.03320.07
5.5.40.0100.03020.06
5.5.30.0030.03720.05
5.5.20.0030.04020.07
5.5.10.0000.03720.07
5.5.00.0030.05319.97
5.4.450.0100.04019.56
5.4.440.0000.08019.52
5.4.430.0100.07719.37
5.4.420.0070.04319.46
5.4.410.0030.07019.35
5.4.400.0170.07318.95
5.4.390.0170.06019.03
5.4.380.0100.07719.03
5.4.370.0070.05019.18
5.4.360.0100.07019.18
5.4.350.0100.05718.95
5.4.340.0000.05019.04
5.4.320.0130.06719.14
5.4.310.0100.07018.95
5.4.300.0130.03019.23
5.4.290.0030.03318.90
5.4.280.0000.04018.90
5.4.270.0070.03319.12
5.4.260.0000.04019.04
5.4.250.0030.03718.87
5.4.240.0070.03319.14
5.4.230.0030.03718.96
5.4.220.0030.03319.20
5.4.210.0100.05318.94
5.4.200.0000.05018.84
5.4.190.0000.04018.93
5.4.180.0100.03019.04
5.4.170.0030.03718.83
5.4.160.0070.03718.93
5.4.150.0030.03719.01
5.4.140.0100.03016.41
5.4.130.0030.03716.41
5.4.120.0070.03716.32
5.4.110.0000.04016.39
5.4.100.0070.03316.39
5.4.90.0100.03316.51
5.4.80.0030.04016.32
5.4.70.0030.03716.49
5.4.60.0030.03316.43
5.4.50.0030.03716.33
5.4.40.0030.03316.36
5.4.30.0000.03716.30
5.4.20.0070.03716.44
5.4.10.0070.03716.40
5.4.00.0000.03015.90
5.3.290.0070.06314.60
5.3.280.0030.03714.59
5.3.270.0000.03314.72
5.3.260.0070.03314.68
5.3.250.0000.04714.58
5.3.240.0000.04014.61
5.3.230.0100.03314.71
5.3.220.0100.03314.52
5.3.210.0000.04014.68
5.3.200.0100.02714.53
5.3.190.0000.03314.71
5.3.180.0030.03314.69
5.3.170.0000.04014.53
5.3.160.0130.02714.52
5.3.150.0000.03314.55
5.3.140.0000.03314.66
5.3.130.0070.03714.48
5.3.120.0000.04014.52
5.3.110.0030.03714.54
5.3.100.0070.03014.18
5.3.90.0030.03014.11
5.3.80.0100.03013.93
5.3.70.0030.03714.00
5.3.60.0070.02713.99
5.3.50.0030.05313.88
5.3.40.0070.04314.09
5.3.30.0030.02714.03
5.3.20.0000.03013.70
5.3.10.0070.03013.76
5.3.00.0030.03713.57
5.2.170.0100.02311.00
5.2.160.0030.03311.06
5.2.150.0030.03311.06
5.2.140.0000.03711.00
5.2.130.0000.03011.21
5.2.120.0000.02311.16
5.2.110.0070.02311.20
5.2.100.0030.02711.13
5.2.90.0030.02711.09
5.2.80.0000.03011.11
5.2.70.0000.02711.00
5.2.60.0030.06711.11
5.2.50.0000.06011.11
5.2.40.0070.05311.14
5.2.30.0030.03311.06
5.2.20.0130.01711.03
5.2.10.0000.05310.86
5.2.00.0070.03310.73
5.1.60.0030.05310.12
5.1.50.0070.03010.07
5.1.40.0000.0309.84
5.1.30.0030.03010.35
5.1.20.0070.02710.27
5.1.10.0030.0279.93
5.1.00.0030.0279.92
5.0.50.0030.0239.74
5.0.40.0000.0239.74
5.0.30.0070.0539.74
5.0.20.0030.0439.74
5.0.10.0100.0309.74
5.0.00.0100.0579.74
4.4.90.0000.0179.74
4.4.80.0030.0339.74
4.4.70.0030.0339.74
4.4.60.0030.0339.74
4.4.50.0070.0309.74
4.4.40.0030.0239.74
4.4.30.0000.0179.74
4.4.20.0030.0279.74
4.4.10.0030.0179.74
4.4.00.0000.0509.74
4.3.110.0030.0279.74
4.3.100.0070.0179.74
4.3.90.0000.0239.74
4.3.80.0070.0239.74
4.3.70.0000.0239.74
4.3.60.0000.0239.74
4.3.50.0030.0239.74
4.3.40.0070.0479.74
4.3.30.0100.0239.74
4.3.20.0000.0339.74
4.3.10.0000.0379.74
4.3.00.0000.0239.74

preferences:
43.8 ms | 400 KiB | 5 Q