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', '.' => '/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.60.0040.01518.68
8.3.50.0070.01022.24
8.3.40.0090.00619.35
8.3.30.0120.00319.21
8.3.20.0040.00419.98
8.3.10.0050.00321.92
8.3.00.0050.00322.58
8.2.180.0070.01117.25
8.2.170.0140.00722.96
8.2.160.0090.00619.16
8.2.150.0060.00324.18
8.2.140.0080.00024.66
8.2.130.0050.00226.16
8.2.120.0030.00519.61
8.2.110.0100.00022.26
8.2.100.0060.00618.03
8.2.90.0040.00419.22
8.2.80.0040.00417.97
8.2.70.0040.00417.88
8.2.60.0030.00617.93
8.2.50.0050.00418.07
8.2.40.0030.00618.47
8.2.30.0040.00418.23
8.2.20.0050.00218.13
8.2.10.0000.00718.11
8.2.00.0030.00618.14
8.1.280.0000.01825.92
8.1.270.0090.00021.96
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0060.00320.21
8.1.230.0080.00317.89
8.1.220.0030.00517.74
8.1.210.0040.00418.77
8.1.200.0030.00617.48
8.1.190.0040.00417.53
8.1.180.0030.00618.84
8.1.170.0080.00018.74
8.1.160.0000.00722.09
8.1.150.0040.00418.85
8.1.140.0080.00317.72
8.1.130.0000.00717.91
8.1.120.0000.00717.60
8.1.110.0000.00817.63
8.1.100.0030.00517.48
8.1.90.0040.00417.60
8.1.80.0000.00817.67
8.1.70.0030.00317.53
8.1.60.0040.00717.75
8.1.50.0040.00417.59
8.1.40.0000.00817.76
8.1.30.0060.00317.86
8.1.20.0050.00317.82
8.1.10.0050.00517.73
8.1.00.0000.00917.71
8.0.300.0030.00618.77
8.0.290.0040.00417.17
8.0.280.0080.00018.54
8.0.270.0030.00317.21
8.0.260.0030.00317.04
8.0.250.0040.00416.99
8.0.240.0000.00717.14
8.0.230.0030.00317.09
8.0.220.0030.00317.04
8.0.210.0030.00317.09
8.0.200.0030.00317.08
8.0.190.0000.00817.11
8.0.180.0000.00717.03
8.0.170.0050.00217.04
8.0.160.0040.00416.90
8.0.150.0000.00716.86
8.0.140.0050.00216.92
8.0.130.0000.00613.50
8.0.120.0050.00317.00
8.0.110.0040.00417.09
8.0.100.0040.00416.94
8.0.90.0040.00417.12
8.0.80.0060.00917.05
8.0.70.0000.00717.10
8.0.60.0040.00417.16
8.0.50.0030.00516.89
8.0.30.0130.00817.21
8.0.20.0120.00717.40
8.0.10.0040.00417.27
8.0.00.0060.01317.06
7.4.330.0000.00515.00
7.4.320.0070.00016.89
7.4.300.0000.00616.79
7.4.290.0000.00716.80
7.4.280.0030.00516.89
7.4.270.0000.00716.79
7.4.260.0090.00016.70
7.4.250.0040.00416.79
7.4.240.0020.00616.84
7.4.230.0070.00016.91
7.4.220.0150.00616.91
7.4.210.0050.01016.84
7.4.200.0000.00716.91
7.4.190.0030.00316.54
7.4.160.0080.01216.77
7.4.150.0180.00017.40
7.4.140.0130.00717.86
7.4.130.0100.00716.82
7.4.120.0100.01116.70
7.4.110.0090.00916.76
7.4.100.0140.00716.74
7.4.90.0090.00916.68
7.4.80.0070.01019.39
7.4.70.0130.01016.74
7.4.60.0030.01716.70
7.4.50.0000.00716.69
7.4.40.0060.00922.77
7.4.30.0140.00316.75
7.4.00.0100.00615.11
7.3.330.0000.00513.53
7.3.320.0000.00513.54
7.3.310.0040.00416.59
7.3.300.0030.00316.55
7.3.290.0100.00316.55
7.3.280.0070.00816.53
7.3.270.0120.00617.40
7.3.260.0120.01216.71
7.3.250.0070.01016.77
7.3.240.0090.00616.72
7.3.230.0060.01016.50
7.3.210.0150.00416.60
7.3.200.0140.00319.39
7.3.190.0070.01016.74
7.3.180.0080.00816.91
7.3.170.0060.01016.55
7.3.160.0040.01916.53
7.3.120.0000.01214.95
7.2.330.0060.01217.00
7.2.320.0090.00916.69
7.2.310.0130.01016.95
7.2.300.0060.01116.80
7.2.290.0030.01316.86
7.2.60.0070.01017.07
7.2.00.0030.00919.69
7.1.200.0030.00916.00
7.1.100.0070.00318.53
7.1.70.0030.01417.39
7.1.60.0060.01619.82
7.1.50.0030.02017.16
7.1.00.0030.09022.32
7.0.200.0060.00816.77
7.0.140.0070.07022.02
7.0.60.0170.03719.84
7.0.50.0030.08317.75
7.0.40.0030.09020.12
7.0.30.0300.03320.18
7.0.20.0300.08020.10
7.0.10.0070.08320.14
7.0.00.0030.04720.10
5.6.280.0030.07720.88
5.6.210.0000.04320.71
5.6.200.0170.03318.24
5.6.190.0100.04720.48
5.6.180.0370.03720.50
5.6.170.0270.09020.47
5.6.160.0130.08020.54
5.6.150.0070.04018.18
5.6.140.0070.04718.30
5.6.130.0070.05718.18
5.6.120.0030.04020.98
5.6.110.0130.06020.99
5.6.100.0100.07321.09
5.6.90.0030.04320.98
5.6.80.0070.05720.39
5.5.350.0300.07020.39
5.5.340.0070.07017.99
5.5.330.0070.08320.35
5.5.320.0470.06020.37
5.5.310.0200.05020.24
5.5.300.0070.05018.09
5.5.290.0070.08018.08
5.5.280.0030.04020.66
5.5.270.0030.05320.96
5.5.260.0070.03720.86
5.5.250.0070.06720.71
5.5.240.0030.08020.13
5.4.450.0170.05019.61
5.4.440.0870.06719.57
5.4.430.0100.05319.54
5.4.420.0170.06719.62
5.4.410.0030.06318.91
5.4.400.0130.06318.80
5.4.390.0070.05718.48
5.4.380.0130.05318.77
5.4.370.0000.04718.73
5.4.360.0070.03718.77
5.4.350.0060.03812.03
5.4.340.0100.04812.03
5.4.320.0070.03612.52
5.4.310.0060.04012.52
5.4.300.0050.04812.51
5.4.290.0060.04412.52
5.4.280.0030.03912.41
5.4.270.0080.03512.41
5.4.260.0130.06318.80
5.4.250.0170.04719.09
5.4.240.0170.04018.99
5.4.230.0100.05018.77
5.4.220.0100.05318.99
5.4.210.0030.05319.09
5.4.200.0200.05018.96
5.4.190.0130.04718.76
5.4.180.0000.05718.89
5.4.170.0100.05018.82
5.4.160.0070.05018.93
5.4.150.0070.07719.09
5.4.140.0130.07016.50
5.4.130.0030.05016.55
5.4.120.0030.05016.54
5.4.110.0130.04316.54
5.4.100.0030.05316.57
5.4.90.0100.06316.43
5.4.80.0100.04316.48
5.4.70.0070.07316.40
5.4.60.0200.03716.51
5.4.50.0100.04316.30
5.4.40.0070.05016.42
5.4.30.0100.04716.30
5.4.20.0030.05016.52
5.4.10.0070.07316.53
5.4.00.0130.04315.91
5.3.290.0070.03812.80
5.3.280.0170.04314.67
5.3.270.0100.07314.57
5.3.260.0030.05314.64
5.3.250.0130.04314.77
5.3.240.0130.06714.67
5.3.230.0000.05714.60
5.3.220.0070.05014.79
5.3.210.0070.06714.47
5.3.200.0070.06014.59
5.3.190.0100.04714.66
5.3.180.0130.06714.57
5.3.170.0070.07314.47
5.3.160.0130.04314.65
5.3.150.0070.05714.58
5.3.140.0170.04714.57
5.3.130.0070.06014.59
5.3.120.0130.05014.54
5.3.110.0070.05314.73
5.3.100.0070.04714.06
5.3.90.0000.05314.02
5.3.80.0000.06314.11
5.3.70.0000.05714.11
5.3.60.0030.05714.09
5.3.50.0130.04313.94
5.3.40.0100.04314.04
5.3.30.0070.05014.00
5.3.20.0070.05013.71
5.3.10.0100.04313.64
5.3.00.0200.04013.72
5.2.170.0070.04711.23
5.2.160.0000.04711.13
5.2.150.0070.04011.23
5.2.140.0070.04011.05
5.2.130.0030.04011.06
5.2.120.0000.04311.01
5.2.110.0100.03311.28
5.2.100.0100.04710.93
5.2.90.0030.06011.05
5.2.80.0030.05311.17
5.2.70.0100.03311.25
5.2.60.0100.03311.04
5.2.50.0070.04711.01
5.2.40.0070.03710.83
5.2.30.0030.04010.80
5.2.20.0070.03711.03
5.2.10.0130.03010.86
5.2.00.0100.03310.80
5.1.60.0070.03010.10
5.1.50.0070.04010.12
5.1.40.0100.03010.02
5.1.30.0030.03710.30
5.1.20.0100.04310.44
5.1.10.0030.03710.08
5.1.00.0130.03710.03
5.0.50.0000.0308.56
5.0.40.0070.0238.38
5.0.30.0000.0438.23
5.0.20.0030.0378.04
5.0.10.0030.0278.38
5.0.00.0030.0438.33
4.4.90.0070.0236.97
4.4.80.0000.0306.97
4.4.70.0070.0236.97
4.4.60.0070.0176.97
4.4.50.0000.0236.97
4.4.40.0030.0406.97
4.4.30.0070.0176.97
4.4.20.0070.0176.97
4.4.10.0070.0176.97
4.4.00.0000.0376.97
4.3.110.0030.0236.97
4.3.100.0030.0206.97
4.3.90.0100.0236.97
4.3.80.0070.0406.97
4.3.70.0030.0276.97
4.3.60.0030.0206.97
4.3.50.0000.0276.97
4.3.40.0070.0336.97
4.3.30.0070.0236.97
4.3.20.0030.0306.97
4.3.10.0000.0306.97
4.3.00.0000.0236.21

preferences:
37.02 ms | 401 KiB | 5 Q