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' => '', ]; 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.0100.01018.64
8.3.50.0130.00522.17
8.3.40.0110.01119.31
8.3.30.0040.01119.27
8.3.20.0040.00420.39
8.3.10.0080.00021.83
8.3.00.0080.00022.38
8.2.180.0060.00918.75
8.2.170.0090.00622.96
8.2.160.0080.00819.39
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00419.63
8.2.110.0090.00022.11
8.2.100.0060.00618.16
8.2.90.0050.00319.35
8.2.80.0040.00418.03
8.2.70.0000.00917.75
8.2.60.0040.00418.16
8.2.50.0040.00418.07
8.2.40.0050.00320.07
8.2.30.0050.00218.31
8.2.20.0040.00418.03
8.2.10.0040.00418.00
8.2.00.0000.01117.95
8.1.280.0110.00725.92
8.1.270.0090.00022.22
8.1.260.0040.00426.35
8.1.250.0060.00328.09
8.1.240.0060.00320.55
8.1.230.0070.00317.83
8.1.220.0060.00318.04
8.1.210.0050.00318.77
8.1.200.0090.00017.48
8.1.190.0040.00417.54
8.1.180.0030.00618.66
8.1.170.0050.00318.76
8.1.160.0000.00722.25
8.1.150.0000.00718.79
8.1.140.0030.00817.71
8.1.130.0030.00317.98
8.1.120.0000.00717.59
8.1.110.0040.00417.67
8.1.100.0040.00417.59
8.1.90.0040.00417.67
8.1.80.0050.00217.59
8.1.70.0030.00317.62
8.1.60.0030.00917.64
8.1.50.0000.00817.74
8.1.40.0030.00517.71
8.1.30.0030.00517.80
8.1.20.0000.00817.78
8.1.10.0000.00817.73
8.1.00.0040.00417.71
8.0.300.0000.00818.77
8.0.290.0000.00717.18
8.0.280.0030.00318.51
8.0.270.0040.00417.30
8.0.260.0030.00317.12
8.0.250.0030.00317.20
8.0.240.0040.00417.10
8.0.230.0040.00417.11
8.0.220.0000.00717.23
8.0.210.0000.00717.10
8.0.200.0000.00717.17
8.0.190.0050.00317.16
8.0.180.0040.00417.18
8.0.170.0000.00717.16
8.0.160.0040.00416.97
8.0.150.0000.00716.98
8.0.140.0030.00517.04
8.0.130.0000.00613.60
8.0.120.0050.00317.21
8.0.110.0030.00517.10
8.0.100.0000.00717.06
8.0.90.0040.00417.22
8.0.80.0030.01217.13
8.0.70.0040.00417.12
8.0.60.0030.00517.14
8.0.50.0000.00817.23
8.0.30.0130.00617.27
8.0.20.0080.01017.41
8.0.10.0040.00417.38
8.0.00.0110.00817.15
7.4.330.0050.00015.00
7.4.320.0030.00316.83
7.4.300.0030.00316.92
7.4.290.0030.00516.86
7.4.280.0030.00316.71
7.4.270.0070.00016.88
7.4.260.0000.00716.73
7.4.250.0030.00516.75
7.4.240.0030.00516.83
7.4.230.0030.00316.62
7.4.220.0110.00716.85
7.4.210.0060.01216.84
7.4.200.0050.00316.66
7.4.190.0040.00416.90
7.4.160.0120.00416.84
7.4.150.0030.01617.40
7.4.140.0060.01117.86
7.4.130.0060.01416.76
7.4.120.0100.00816.95
7.4.110.0130.01016.85
7.4.100.0130.00616.73
7.4.90.0150.00416.79
7.4.80.0060.01519.39
7.4.70.0180.00016.67
7.4.60.0140.00416.81
7.4.50.0020.00216.71
7.4.40.0130.00322.77
7.4.30.0130.00916.81
7.4.00.0070.01015.17
7.3.330.0030.00313.60
7.3.320.0000.00613.54
7.3.310.0000.00816.50
7.3.300.0000.00616.48
7.3.290.0100.00316.54
7.3.280.0090.01016.58
7.3.270.0140.00317.40
7.3.260.0160.00616.61
7.3.250.0130.00316.74
7.3.240.0070.01016.88
7.3.230.0100.00716.60
7.3.210.0110.00616.72
7.3.200.0070.01119.39
7.3.190.0030.01516.81
7.3.180.0060.00916.87
7.3.170.0100.00616.73
7.3.160.0090.00916.73
7.3.120.0070.00715.27
7.3.10.0080.00816.92
7.3.00.0060.00616.92
7.2.330.0130.01716.80
7.2.320.0150.00616.95
7.2.310.0060.01616.90
7.2.300.0090.01316.81
7.2.290.0070.01016.83
7.2.130.0040.01017.14
7.2.120.0000.01317.11
7.2.110.0000.01116.87
7.2.100.0060.00617.11
7.2.90.0000.01417.29
7.2.80.0030.00617.14
7.2.70.0060.00917.13
7.2.60.0060.00617.06
7.2.50.0070.01017.12
7.2.40.0070.00717.16
7.2.30.0070.00717.36
7.2.20.0000.01117.06
7.2.10.0060.01017.18
7.2.00.0110.00317.12
7.1.250.0000.01215.64
7.1.70.0000.01017.05
7.1.60.0040.00817.18
7.1.50.0070.01016.90
7.1.00.0030.08022.29
7.0.200.0060.00917.04
7.0.140.0070.07021.98
7.0.60.0030.04020.00
7.0.50.0030.05717.75
7.0.40.0070.06320.11
7.0.30.0230.07020.12
7.0.20.0530.06320.21
7.0.10.0100.03720.25
7.0.00.0100.08320.08
5.6.280.0000.07720.92
5.6.210.0070.08020.51
5.6.200.0070.07718.28
5.6.190.0030.05720.46
5.6.180.0230.06320.42
5.6.170.0200.05020.71
5.6.160.0030.09020.46
5.6.150.0030.06718.15
5.6.140.0130.07318.29
5.6.130.0100.07318.21
5.6.120.0130.04021.15
5.6.110.0100.07721.02
5.6.100.0030.08720.99
5.6.90.0100.08020.98
5.6.80.0070.05320.30
5.5.350.0330.07320.42
5.5.340.0030.07718.04
5.5.330.0130.05720.56
5.5.320.0370.06320.37
5.5.310.0230.07320.28
5.5.300.0130.07717.98
5.5.290.0200.05717.95
5.5.280.0030.07020.86
5.5.270.0170.07320.88
5.5.260.0100.06720.77
5.5.250.0130.07720.70
5.5.240.0200.07320.27
5.4.450.0700.06319.33
5.4.440.0800.08019.61
5.4.430.0070.05719.36
5.4.420.0170.07019.48
5.4.410.0030.06018.81
5.4.400.0030.05718.67
5.4.390.0070.05718.52
5.4.380.0130.05018.51
5.4.370.0200.06018.56
5.4.360.0230.05018.80
5.4.350.0170.05718.59
5.4.340.0270.05018.73
5.4.320.0070.03612.52
5.4.310.0080.03812.51
5.4.300.0070.04012.51
5.4.290.0070.04612.51
5.4.280.0050.03912.41
5.4.270.0060.03612.41
5.4.260.0130.05019.01
5.4.250.0100.06319.01
5.4.240.0070.06019.00
5.4.230.0100.06018.99
5.4.220.0130.07718.65
5.4.210.0070.05318.90
5.4.200.0130.04718.77
5.4.190.0100.05018.95
5.4.180.0070.07718.95
5.4.170.0100.05718.79
5.4.160.0030.07019.01
5.4.150.0130.06318.94
5.4.140.0170.05316.45
5.4.130.0200.04016.38
5.4.120.0170.04316.43
5.4.110.0000.06016.64
5.4.100.0000.05316.50
5.4.90.0100.04716.56
5.4.80.0230.04316.63
5.4.70.0030.05016.35
5.4.60.0070.05716.48
5.4.50.0100.06316.48
5.4.40.0070.05716.64
5.4.30.0070.06016.50
5.4.20.0030.05316.30
5.4.10.0130.04316.30
5.4.00.0130.04015.84
5.3.290.0070.04712.80
5.3.280.0170.06714.60
5.3.270.0100.05014.63
5.3.260.0070.07314.75
5.3.250.0130.05014.68
5.3.240.0000.06014.74
5.3.230.0200.03714.69
5.3.220.0030.05714.47
5.3.210.0100.04714.55
5.3.200.0030.05014.74
5.3.190.0130.05314.57
5.3.180.0030.05314.56
5.3.170.0200.05714.63
5.3.160.0070.05014.53
5.3.150.0030.05714.75
5.3.140.0130.04714.63
5.3.130.0200.04714.63
5.3.120.0070.05014.61
5.3.110.0000.06714.57
5.3.100.0070.06014.06
5.3.90.0000.06013.85
5.3.80.0130.04314.06
5.3.70.0100.05014.04
5.3.60.0200.04314.23
5.3.50.0070.05714.02
5.3.40.0130.06714.12
5.3.30.0070.04713.89
5.3.20.0130.06713.78
5.3.10.0170.04313.48
5.3.00.0070.04713.61
5.2.170.0070.04011.10
5.2.160.0100.04011.31
5.2.150.0170.03711.33
5.2.140.0030.05011.23
5.2.130.0130.03311.18
5.2.120.0100.03711.11
5.2.110.0100.05011.11
5.2.100.0030.04011.08
5.2.90.0000.04711.28
5.2.80.0130.04310.99
5.2.70.0100.05011.06
5.2.60.0070.04311.04
5.2.50.0100.04711.09
5.2.40.0030.04011.07
5.2.30.0030.04311.15
5.2.20.0070.04311.03
5.2.10.0030.04010.77
5.2.00.0100.03710.80
5.1.60.0070.03310.20
5.1.50.0130.02310.05
5.1.40.0070.0309.98
5.1.30.0130.02310.41
5.1.20.0130.02710.19
5.1.10.0070.0379.91
5.1.00.0070.05010.23
5.0.50.0070.0238.62
5.0.40.0000.0338.39
5.0.30.0100.0478.27
5.0.20.0030.0278.44
5.0.10.0070.0338.27
5.0.00.0070.0538.26
4.4.90.0070.0176.73
4.4.80.0030.0306.73
4.4.70.0070.0176.73
4.4.60.0070.0276.73
4.4.50.0100.0136.73
4.4.40.0030.0306.73
4.4.30.0030.0236.73
4.4.20.0030.0236.73
4.4.10.0000.0236.73
4.4.00.0000.0336.73
4.3.110.0100.0136.73
4.3.100.0000.0236.73
4.3.90.0030.0236.73
4.3.80.0070.0406.73
4.3.70.0070.0176.73
4.3.60.0070.0236.73
4.3.50.0070.0236.73
4.3.40.0030.0306.73
4.3.30.0000.0236.73
4.3.20.0070.0236.73
4.3.10.0070.0176.73
4.3.00.0100.0236.73

preferences:
41.63 ms | 401 KiB | 5 Q