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) : []; var_dump($target); // Strip empty components and resolve . and .. foreach (preg_split('#[\\\\/]+#', $path, -1, PREG_SPLIT_NO_EMPTY) as $component) { var_dump($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.0160.01018.68
8.3.60.0100.01018.79
8.3.50.0080.01022.19
8.3.40.0120.00319.12
8.3.30.0040.01219.18
8.3.20.0090.00020.16
8.3.10.0030.00522.16
8.3.00.0040.00422.58
8.2.180.0060.01617.00
8.2.170.0150.00022.96
8.2.160.0170.00319.20
8.2.150.0000.01424.18
8.2.140.0030.00624.66
8.2.130.0040.00426.16
8.2.120.0050.00319.61
8.2.110.0080.00322.00
8.2.100.0090.00318.22
8.2.90.0050.00319.40
8.2.80.0040.00418.03
8.2.70.0060.00318.00
8.2.60.0040.00418.16
8.2.50.0050.00318.07
8.2.40.0030.00618.28
8.2.30.0040.00418.10
8.2.20.0000.00718.09
8.2.10.0000.00818.00
8.2.00.0040.00718.04
8.1.280.0090.00925.92
8.1.270.0070.00022.11
8.1.260.0030.00526.35
8.1.250.0040.00428.09
8.1.240.0030.00620.39
8.1.230.0080.00317.89
8.1.220.0040.00417.79
8.1.210.0030.00518.77
8.1.200.0060.00317.60
8.1.190.0050.00317.42
8.1.180.0050.00318.73
8.1.170.0090.00018.79
8.1.160.0070.00022.05
8.1.150.0040.00418.86
8.1.140.0100.00017.68
8.1.130.0030.00317.83
8.1.120.0030.00617.62
8.1.110.0030.00517.60
8.1.100.0040.00417.59
8.1.90.0000.00717.61
8.1.80.0060.00317.57
8.1.70.0040.00417.52
8.1.60.0000.01017.79
8.1.50.0000.00817.66
8.1.40.0040.00417.68
8.1.30.0080.00017.74
8.1.20.0040.00417.76
8.1.10.0080.00017.77
8.1.00.0000.00817.66
8.0.300.0040.00418.77
8.0.290.0000.00717.05
8.0.280.0050.00218.52
8.0.270.0000.00717.27
8.0.260.0030.00316.90
8.0.250.0030.00316.98
8.0.240.0040.00417.00
8.0.230.0000.00717.11
8.0.220.0030.00317.03
8.0.210.0070.00016.98
8.0.200.0080.00017.03
8.0.190.0050.00316.99
8.0.180.0000.00816.95
8.0.170.0000.00717.04
8.0.160.0000.00717.07
8.0.150.0060.00316.89
8.0.140.0040.00417.02
8.0.130.0050.00013.44
8.0.120.0040.00417.08
8.0.110.0000.00816.99
8.0.100.0040.00416.91
8.0.90.0000.00816.91
8.0.80.0000.01617.11
8.0.70.0020.00517.17
8.0.60.0040.00416.97
8.0.50.0030.00517.04
8.0.30.0080.01017.34
8.0.20.0120.00717.40
8.0.10.0050.00317.30
8.0.00.0120.00616.81
7.4.330.0050.00015.00
7.4.320.0000.00716.86
7.4.300.0030.00316.68
7.4.290.0070.00016.87
7.4.280.0030.00316.88
7.4.270.0030.00316.90
7.4.260.0080.00016.86
7.4.250.0040.00416.75
7.4.240.0070.00016.86
7.4.230.0070.00016.93
7.4.220.0130.00716.75
7.4.210.0110.00716.80
7.4.200.0080.00016.91
7.4.190.0040.00316.82
7.4.160.0120.00416.79
7.4.150.0120.00617.40
7.4.140.0110.00817.86
7.4.130.0070.01016.90
7.4.120.0070.01016.73
7.4.110.0090.00916.88
7.4.100.0040.01416.61
7.4.90.0120.00616.92
7.4.80.0100.01119.39
7.4.70.0100.01616.70
7.4.60.0070.01016.71
7.4.50.0090.00016.37
7.4.40.0070.00722.77
7.4.30.0090.01216.54
7.4.00.0060.00615.26
7.3.330.0050.00013.43
7.3.320.0030.00313.48
7.3.310.0000.00816.53
7.3.300.0000.00716.38
7.3.290.0100.00316.53
7.3.280.0100.01016.54
7.3.270.0000.02417.40
7.3.260.0120.00616.54
7.3.250.0140.00616.66
7.3.240.0110.00716.80
7.3.230.0140.00416.65
7.3.210.0170.00016.46
7.3.200.0060.00919.39
7.3.190.0110.01216.71
7.3.180.0100.00616.64
7.3.170.0120.00616.61
7.3.160.0110.00916.59
7.3.120.0120.00614.76
7.3.110.0100.00615.16
7.3.100.0060.01114.89
7.3.90.0030.01315.07
7.3.80.0050.00514.74
7.3.70.0030.01314.77
7.3.60.0030.01315.15
7.3.50.0050.00514.89
7.3.40.0060.00915.01
7.3.30.0060.00315.02
7.3.20.0060.01116.85
7.3.10.0070.01016.57
7.3.00.0040.00716.92
7.2.330.0060.01616.87
7.2.320.0090.01016.92
7.2.310.0150.00617.02
7.2.300.0060.01616.81
7.2.290.0030.01316.91
7.2.240.0060.01215.36
7.2.230.0000.01315.13
7.2.220.0080.00815.34
7.2.210.0110.00415.38
7.2.200.0030.01215.24
7.2.190.0110.00415.18
7.2.180.0090.00615.32
7.2.170.0070.00415.05
7.2.160.0080.00415.10
7.2.150.0080.00817.22
7.2.140.0080.00317.10
7.2.130.0090.00016.99
7.2.120.0070.01017.05
7.2.110.0130.00017.23
7.2.100.0080.00817.13
7.2.90.0070.00317.30
7.2.80.0060.01016.97
7.2.70.0030.01217.36
7.2.60.0120.00017.23
7.2.50.0060.00916.90
7.2.40.0110.00417.17
7.2.30.0060.00317.26
7.2.20.0110.00717.08
7.2.10.0070.01017.14
7.2.00.0050.00818.41
7.1.330.0030.01015.87
7.1.320.0070.00715.80
7.1.310.0030.01316.03
7.1.300.0090.00316.10
7.1.290.0000.01115.79
7.1.280.0090.00315.91
7.1.270.0030.01316.00
7.1.260.0030.01315.99
7.1.250.0030.01216.17
7.1.100.0120.00018.19
7.1.70.0030.00517.36
7.1.60.0130.01019.82
7.1.50.0190.00017.25
7.1.00.0070.07322.29
7.0.200.0040.00417.05
7.0.140.0030.07722.04
7.0.60.0100.08319.90
7.0.50.0100.07717.92
7.0.40.0070.07020.32
7.0.30.0330.07720.25
7.0.20.0200.07320.07
7.0.10.0230.05720.07
7.0.00.0100.05320.27
5.6.210.0070.04720.78
5.6.200.0070.05318.18
5.6.190.0130.08320.77
5.6.180.3700.05020.40
5.6.170.0200.06720.55
5.6.160.0100.08720.46
5.6.150.0130.06318.16
5.6.140.0000.04318.19
5.6.130.0070.07718.18
5.6.120.0170.06721.00
5.6.110.0070.05720.91
5.6.100.0030.08720.95
5.6.90.0130.06721.11
5.6.80.0100.08020.52
5.6.70.4470.03720.41
5.5.350.0000.08320.39
5.5.340.0130.04718.08
5.5.330.0130.07020.47
5.5.320.0300.06720.36
5.5.310.0300.07320.28
5.5.300.0100.07018.05
5.5.290.0100.04018.04
5.5.280.0030.04320.82
5.5.270.0030.04320.69
5.5.260.0070.06720.88
5.5.250.0030.09020.63
5.5.240.0000.06320.22
5.4.450.0730.03719.73
5.4.440.0400.06019.31
5.4.430.0430.04719.45
5.4.420.0500.05019.47
5.4.410.0500.05019.34
5.4.400.4870.00018.85
5.4.390.0830.00018.77
5.4.380.0200.06318.63
5.4.370.0670.05718.76
5.4.360.1000.04718.63
5.4.350.0870.05318.48
5.4.340.1070.05718.57
5.4.320.0100.04112.52
5.4.310.0040.04012.51
5.4.300.0120.03412.51
5.4.290.0060.04312.51
5.4.280.0070.03412.40
5.4.270.0060.04012.41
5.4.260.0130.04718.81
5.4.250.0030.05718.99
5.4.240.0030.05718.82
5.4.230.0070.05018.92
5.4.220.0100.05018.93
5.4.210.0130.05318.95
5.4.200.0100.05019.08
5.4.190.0100.06018.95
5.4.180.0070.05718.65
5.4.170.0100.05718.89
5.4.160.0130.04318.98
5.4.150.0200.06018.80
5.4.140.0030.06316.44
5.4.130.0000.05316.45
5.4.120.0070.05016.37
5.4.110.0070.04716.51
5.4.100.0070.06316.42
5.4.90.0070.04716.57
5.4.80.0070.05016.55
5.4.70.0030.05316.39
5.4.60.0130.04316.62
5.4.50.0130.04316.48
5.4.40.0130.04316.67
5.4.30.0100.04716.34
5.4.20.0100.04316.50
5.4.10.0130.04716.38
5.4.00.0030.05715.82
5.3.290.0080.04312.80
5.3.280.0070.05014.67
5.3.270.0130.05014.59
5.3.260.0000.07014.60
5.3.250.0130.05314.76
5.3.240.0070.05014.77
5.3.230.0030.05714.61
5.3.220.0170.06014.66
5.3.210.0130.04314.73
5.3.200.0130.04014.47
5.3.190.0070.05014.79
5.3.180.0000.05714.57
5.3.170.0070.05014.64
5.3.160.0000.05314.54
5.3.150.0170.05014.65
5.3.140.0030.05314.62
5.3.130.0070.05314.79
5.3.120.0030.05714.71
5.3.110.0070.05314.46
5.3.100.0070.06713.89
5.3.90.0070.05014.10
5.3.80.0130.04013.85
5.3.70.0000.05313.99
5.3.60.0070.05013.99
5.3.50.0030.05713.93
5.3.40.0130.04713.94
5.3.30.0000.07714.13
5.3.20.0100.05013.68
5.3.10.0200.04013.48
5.3.00.0070.05013.61
5.2.170.0000.04711.11
5.2.160.0100.05011.14
5.2.150.0000.05011.22
5.2.140.0100.03711.13
5.2.130.0000.04311.18
5.2.120.0070.03711.20
5.2.110.0130.05011.06
5.2.100.0070.03711.07
5.2.90.0000.04311.05
5.2.80.0100.03311.16
5.2.70.0030.04011.01
5.2.60.0070.04311.23
5.2.50.0070.05711.02
5.2.40.0130.03711.07
5.2.30.0030.05711.07
5.2.20.0030.04011.04
5.2.10.0100.04010.77
5.2.00.0170.02710.88
5.1.60.0070.03010.00
5.1.50.0070.0309.93
5.1.40.0070.0409.90
5.1.30.0130.03010.39
5.1.20.0100.03010.54
5.1.10.0130.03310.14
5.1.00.0030.03710.04
5.0.50.0000.0308.70
5.0.40.0130.0208.34
5.0.30.0030.0578.21
5.0.20.0000.0408.15
5.0.10.0030.0378.13
5.0.00.0030.0408.26
4.4.90.0000.0236.68
4.4.80.0030.0236.68
4.4.70.0070.0176.68
4.4.60.0070.0176.68
4.4.50.0000.0236.68
4.4.40.0000.0336.68
4.4.30.0000.0236.68
4.4.20.0000.0306.68
4.4.10.0000.0276.68
4.4.00.0000.0376.68
4.3.110.0070.0176.68
4.3.100.0130.0106.68
4.3.90.0030.0206.68
4.3.80.0030.0336.68
4.3.70.0100.0236.68
4.3.60.0000.0206.68
4.3.50.0070.0206.68
4.3.40.0100.0276.68
4.3.30.0030.0276.68
4.3.20.0000.0236.68
4.3.10.0030.0206.68
4.3.00.0070.0206.80

preferences:
44.81 ms | 401 KiB | 5 Q