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) { array_unshift($target, $separator); } return implode($separator, $target); } $tests = [ '/foo/bar/./../baz' => null, ]; 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.70.0090.01317.12
8.3.60.0140.00718.55
8.3.50.0060.00922.04
8.3.40.0110.00419.08
8.3.30.0110.01119.18
8.3.20.0050.00320.20
8.3.10.0000.00821.95
8.3.00.0040.00422.57
8.2.180.0070.00716.75
8.2.170.0080.00822.96
8.2.160.0090.00619.13
8.2.150.0120.00324.18
8.2.140.0030.00624.66
8.2.130.0050.00326.16
8.2.120.0050.00319.61
8.2.110.0090.00020.46
8.2.100.0060.00618.03
8.2.90.0040.00419.36
8.2.80.0000.00817.97
8.2.70.0050.00317.88
8.2.60.0040.00818.05
8.2.50.0060.00318.10
8.2.40.0080.00018.22
8.2.30.0040.00418.30
8.2.20.0000.00718.10
8.2.10.0040.00417.93
8.2.00.0040.00718.10
8.1.280.0110.00425.92
8.1.270.0090.00022.09
8.1.260.0000.00826.35
8.1.250.0080.00028.09
8.1.240.0090.00022.46
8.1.230.0080.00817.70
8.1.220.0030.00617.91
8.1.210.0070.00318.77
8.1.200.0030.00617.73
8.1.190.0040.00417.60
8.1.180.0080.00018.10
8.1.170.0040.00418.79
8.1.160.0000.00722.20
8.1.150.0050.00318.89
8.1.140.0080.00417.58
8.1.130.0070.00017.86
8.1.120.0000.00717.65
8.1.110.0030.00517.56
8.1.100.0040.00417.63
8.1.90.0080.00017.55
8.1.80.0050.00217.65
8.1.70.0030.00317.62
8.1.60.0070.00417.76
8.1.50.0040.00417.67
8.1.40.0040.00417.66
8.1.30.0000.00717.72
8.1.20.0000.00817.70
8.1.10.0050.00317.67
8.1.00.0000.00717.61
8.0.300.0040.00418.77
8.0.290.0000.00816.88
8.0.280.0030.00318.38
8.0.270.0040.00417.23
8.0.260.0000.00716.92
8.0.250.0030.00317.04
8.0.240.0000.00717.18
8.0.230.0030.00317.11
8.0.220.0070.00017.11
8.0.210.0030.00317.18
8.0.200.0050.00317.15
8.0.190.0000.00717.13
8.0.180.0050.00317.09
8.0.170.0080.00017.11
8.0.160.0000.00816.96
8.0.150.0080.00017.04
8.0.140.0040.00417.08
8.0.130.0030.00313.44
8.0.120.0000.00717.10
8.0.110.0050.00217.11
8.0.100.0040.00417.04
8.0.90.0040.00417.02
8.0.80.0060.00917.20
8.0.70.0050.00317.11
8.0.60.0000.00817.09
8.0.50.0000.00717.20
8.0.30.0110.00917.18
8.0.20.0060.01217.40
8.0.10.0050.00217.38
8.0.00.0110.00716.91
7.4.330.0000.00615.00
7.4.320.0030.00316.93
7.4.300.0060.00016.86
7.4.290.0070.00016.82
7.4.280.0080.00016.76
7.4.270.0070.00016.97
7.4.260.0030.00516.82
7.4.250.0040.00416.90
7.4.240.0020.00616.82
7.4.230.0040.00416.66
7.4.220.0090.00917.02
7.4.210.0060.00916.85
7.4.200.0050.00316.67
7.4.190.0070.00016.91
7.4.160.0090.00616.76
7.4.150.0140.00917.40
7.4.140.0100.00817.86
7.4.130.0070.01116.84
7.4.120.0110.00716.80
7.4.110.0180.00016.72
7.4.100.0140.00716.91
7.4.90.0100.00716.70
7.4.80.0060.01219.39
7.4.70.0110.00716.66
7.4.60.0030.01316.80
7.4.50.0030.00516.56
7.4.40.0060.01022.77
7.4.30.0060.01616.83
7.4.00.0090.00615.44
7.3.330.0030.00313.60
7.3.320.0000.00613.53
7.3.310.0030.00316.55
7.3.300.0040.00416.55
7.3.290.0150.00616.55
7.3.280.0090.01016.54
7.3.270.0100.00717.40
7.3.260.0090.00916.54
7.3.250.0090.01016.64
7.3.240.0100.00716.68
7.3.230.0100.00716.56
7.3.210.0100.01016.78
7.3.200.0030.01319.39
7.3.190.0110.00716.54
7.3.180.0100.00616.50
7.3.170.0030.01216.63
7.3.160.0110.01116.73
7.3.120.0060.00315.28
7.3.110.0040.00715.32
7.3.100.0090.00915.23
7.3.90.0030.01015.07
7.3.80.0040.01115.21
7.3.70.0120.00314.79
7.3.60.0000.01115.04
7.3.50.0090.00615.09
7.3.40.0030.01014.93
7.3.30.0030.01014.92
7.3.20.0060.00616.80
7.3.10.0120.00616.88
7.3.00.0040.00716.84
7.2.330.0160.00616.89
7.2.320.0100.00916.85
7.2.310.0090.00917.01
7.2.300.0100.01016.84
7.2.290.0120.00416.83
7.2.240.0000.01015.38
7.2.230.0120.00415.40
7.2.220.0090.00615.12
7.2.210.0070.01015.05
7.2.200.0030.01015.39
7.2.190.0030.01015.27
7.2.180.0030.01415.32
7.2.170.0000.01615.20
7.2.160.0090.00615.30
7.2.150.0040.01517.20
7.2.140.0070.00717.10
7.2.130.0040.01217.03
7.2.120.0000.01117.16
7.2.110.0090.00617.13
7.2.100.0080.00816.81
7.2.90.0030.01017.05
7.2.80.0070.00716.98
7.2.70.0120.00616.93
7.2.60.0090.00616.83
7.2.50.0060.01017.11
7.2.40.0110.00417.12
7.2.30.0030.01317.18
7.2.20.0030.01117.23
7.2.10.0090.00617.07
7.2.00.0080.00518.42
7.1.330.0070.00415.76
7.1.320.0040.00816.02
7.1.310.0060.00616.21
7.1.300.0100.00315.79
7.1.290.0100.00715.80
7.1.280.0030.01415.80
7.1.270.0100.00615.80
7.1.260.0130.00016.20
7.1.250.0030.01015.99
7.1.100.0080.00818.53
7.1.70.0070.00317.39
7.1.60.0030.01719.82
7.1.50.0130.00717.11
7.1.00.0030.07722.41
7.0.200.0030.00717.03
7.0.140.0030.07722.19
7.0.100.0030.04019.96
7.0.90.0030.08319.95
7.0.80.0070.04319.89
7.0.70.0000.05319.90
7.0.60.0030.04319.90
7.0.50.0070.04020.29
7.0.40.0070.04020.00
7.0.30.0030.03720.08
7.0.20.0030.04320.18
7.0.10.0070.04720.08
7.0.00.0000.06020.14
5.6.280.0000.07721.14
5.6.250.0100.05020.73
5.6.240.0070.08320.64
5.6.230.0070.04320.70
5.6.220.0030.04020.63
5.6.210.0030.04320.47
5.6.200.0000.04721.15
5.6.190.0030.04721.05
5.6.180.0030.04020.93
5.6.170.0070.03721.05
5.6.160.0070.03720.97
5.6.150.0030.04321.14
5.6.140.0000.04721.03
5.6.130.0030.04021.04
5.6.120.0000.04720.93
5.6.110.0030.04321.11
5.6.100.0070.04321.05
5.6.90.0100.03320.97
5.6.80.0070.04320.41
5.6.70.0070.04020.39
5.6.60.0030.04020.46
5.6.50.0030.04320.45
5.6.40.0030.04320.50
5.6.30.0030.04020.27
5.6.20.0000.04320.44
5.6.10.0070.03720.30
5.6.00.0030.03720.30
5.5.380.0070.04020.34
5.5.370.0130.03020.37
5.5.360.0070.06020.42
5.5.350.0130.05320.48
5.5.340.0100.03320.90
5.5.330.0000.04320.90
5.5.320.0100.03020.80
5.5.310.0070.03720.89
5.5.300.0030.05020.91
5.5.290.0070.08020.87
5.5.280.0130.04020.93
5.5.270.0000.05320.91
5.5.260.0070.04020.93
5.5.250.0030.03720.58
5.5.240.0000.05020.04
5.5.230.0030.04320.25
5.5.220.0000.04720.32
5.5.210.0030.04020.19
5.5.200.0070.03720.27
5.5.190.0030.07320.16
5.5.180.0100.05020.16
5.5.160.0030.04020.14
5.5.150.0100.03320.16
5.5.140.0030.04719.98
5.5.130.0000.03320.16
5.5.120.0000.04320.16
5.5.110.0030.04020.28
5.5.100.0000.03720.09
5.5.90.0100.03720.02
5.5.80.0000.03720.16
5.5.70.0070.03719.95
5.5.60.0070.04320.17
5.5.50.0030.07720.16
5.5.40.0070.07020.16
5.5.30.0100.07020.14
5.5.20.0000.04320.06
5.5.10.0100.06320.04
5.5.00.0070.05719.97
5.4.450.0030.07319.18
5.4.440.0030.06319.53
5.4.430.0030.04019.20
5.4.420.0000.04319.46
5.4.410.0070.03719.34
5.4.400.0000.06318.91
5.4.390.0070.04018.88
5.4.380.0030.03718.95
5.4.370.0030.03018.88
5.4.360.0000.03319.03
5.4.350.0030.04019.04
5.4.340.0070.04019.18
5.4.320.0030.03719.14
5.4.310.0030.03719.21
5.4.300.0100.03018.94
5.4.290.0030.04018.90
5.4.280.0070.04019.15
5.4.270.0100.03019.04
5.4.260.0030.04018.84
5.4.250.0070.04019.11
5.4.240.0100.02319.04
5.4.230.0000.03319.22
5.4.220.0070.04318.88
5.4.210.0030.07019.17
5.4.200.0130.07018.93
5.4.190.0170.06319.20
5.4.180.0030.06319.03
5.4.170.0030.08019.04
5.4.160.0030.03719.12
5.4.150.0030.07319.02
5.4.140.0030.06716.44
5.4.130.0170.06316.43
5.4.120.0000.04016.41
5.4.110.0030.08316.50
5.4.100.0000.03716.53
5.4.90.0000.08016.42
5.4.80.0100.04716.34
5.4.70.0030.06716.38
5.4.60.0070.03316.42
5.4.50.0100.03716.41
5.4.40.0070.07016.41
5.4.30.0030.06316.46
5.4.20.0030.07016.44
5.4.10.0000.07716.39
5.4.00.0100.05315.78
5.3.290.0130.03714.70
5.3.280.0070.05014.66
5.3.270.0030.03714.64
5.3.260.0100.03314.67
5.3.250.0100.07014.59
5.3.240.0070.07714.66
5.3.230.0070.06314.56
5.3.220.0070.05714.62
5.3.210.0030.06714.57
5.3.200.0030.07314.57
5.3.190.0030.07014.66
5.3.180.0070.05314.52
5.3.170.0030.06314.54
5.3.160.0070.06014.58
5.3.150.0000.05014.63
5.3.140.0000.06314.53
5.3.130.0030.06014.66
5.3.120.0070.07714.53
5.3.110.0000.04014.52
5.3.100.0070.07313.96
5.3.90.0070.07014.01
5.3.80.0070.06714.00
5.3.70.0070.03014.11
5.3.60.0070.03314.11
5.3.50.0030.03714.07
5.3.40.0100.07013.93
5.3.30.0100.02713.83
5.3.20.0000.07713.82
5.3.10.0070.04013.65
5.3.00.0170.06713.53
5.2.170.0030.06311.54
5.2.160.0030.03011.54
5.2.150.0030.04311.54
5.2.140.0070.02311.54
5.2.130.0030.06311.54
5.2.120.0030.05011.54
5.2.110.0030.03711.54
5.2.100.0030.03311.54
5.2.90.0000.06311.54
5.2.80.0030.06311.54
5.2.70.0070.05311.54
5.2.60.0030.05711.54
5.2.50.0030.06011.54
5.2.40.0100.05711.54
5.2.30.0000.05311.54
5.2.20.0070.06711.54
5.2.10.0030.04011.54
5.2.00.0030.03311.54
5.1.60.0130.03711.54
5.1.50.0030.02311.54
5.1.40.0070.02711.54
5.1.30.0100.04011.54
5.1.20.0000.03311.54
5.1.10.0070.04711.54
5.1.00.0000.04311.54
5.0.50.0030.04311.54
5.0.40.0130.03311.54
5.0.30.0030.03011.54
5.0.20.0030.02311.54
5.0.10.0030.04311.54
5.0.00.0070.05711.54
4.4.90.0030.03011.54
4.4.80.0030.03311.54
4.4.70.0030.03711.54
4.4.60.0070.02311.54
4.4.50.0070.03311.54
4.4.40.0000.03311.54
4.4.30.0100.02011.54
4.4.20.0000.03711.54
4.4.10.0070.01311.54
4.4.00.0030.05311.54
4.3.110.0000.02011.54
4.3.100.0030.03311.54
4.3.90.0000.02311.54
4.3.80.0000.04311.54
4.3.70.0030.02711.54
4.3.60.0030.02311.54
4.3.50.0000.02711.54
4.3.40.0000.03011.54
4.3.30.0000.01711.54
4.3.20.0030.01711.54
4.3.10.0030.03011.54
4.3.00.0000.03311.54

preferences:
50.33 ms | 404 KiB | 6 Q