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) { 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.60.0140.00718.66
8.3.50.0120.00522.18
8.3.40.0150.00019.21
8.3.30.0120.00919.07
8.3.20.0000.00720.34
8.3.10.0050.00322.00
8.3.00.0050.00322.44
8.2.180.0130.00618.79
8.2.170.0110.00422.96
8.2.160.0140.00719.24
8.2.150.0060.01024.18
8.2.140.0030.00724.66
8.2.130.0040.00426.16
8.2.120.0000.00819.48
8.2.110.0080.00019.31
8.2.100.0090.00318.16
8.2.90.0000.00819.36
8.2.80.0050.00317.97
8.2.70.0040.00417.88
8.2.60.0030.00618.04
8.2.50.0000.00918.10
8.2.40.0000.00818.22
8.2.30.0040.00418.10
8.2.20.0050.00218.15
8.2.10.0080.00018.17
8.2.00.0000.01118.09
8.1.280.0000.01425.92
8.1.270.0080.00022.24
8.1.260.0000.00826.35
8.1.250.0080.00028.09
8.1.240.0070.00323.73
8.1.230.0110.00021.03
8.1.220.0090.00017.88
8.1.210.0030.00518.77
8.1.200.0060.00317.60
8.1.190.0040.00417.60
8.1.180.0030.00518.10
8.1.170.0050.00318.71
8.1.160.0040.00422.13
8.1.150.0000.00718.74
8.1.140.0060.00317.58
8.1.130.0030.00317.93
8.1.120.0070.00017.63
8.1.110.0000.00817.57
8.1.100.0040.00417.65
8.1.90.0000.00717.64
8.1.80.0050.00317.63
8.1.70.0040.00417.61
8.1.60.0030.00917.73
8.1.50.0030.00617.56
8.1.40.0000.00817.65
8.1.30.0090.00017.69
8.1.20.0040.00417.81
8.1.10.0040.00417.77
8.1.00.0040.00417.70
8.0.300.0040.00418.77
8.0.290.0030.00616.75
8.0.280.0030.00318.38
8.0.270.0030.00517.29
8.0.260.0040.00416.90
8.0.250.0030.00317.11
8.0.240.0060.00317.13
8.0.230.0070.00017.11
8.0.220.0030.00317.08
8.0.210.0030.00317.13
8.0.200.0040.00416.95
8.0.190.0040.00417.10
8.0.180.0070.00017.14
8.0.170.0070.00016.98
8.0.160.0000.00716.91
8.0.150.0040.00417.00
8.0.140.0040.00416.91
8.0.130.0060.00013.40
8.0.120.0040.00416.97
8.0.110.0040.00416.95
8.0.100.0030.00617.11
8.0.90.0040.00417.10
8.0.80.0070.00717.09
8.0.70.0040.00417.23
8.0.60.0000.00817.12
8.0.50.0040.00417.06
8.0.30.0080.01117.24
8.0.20.0150.00717.48
8.0.10.0050.00317.25
8.0.00.0160.00416.95
7.4.330.0050.00015.00
7.4.320.0000.00716.89
7.4.300.0060.00016.81
7.4.290.0030.00316.84
7.4.280.0000.00716.77
7.4.270.0000.00716.86
7.4.260.0030.00616.79
7.4.250.0000.00716.85
7.4.240.0010.00616.88
7.4.230.0080.00016.93
7.4.220.0140.00416.85
7.4.210.0070.01016.93
7.4.200.0000.00816.98
7.4.190.0000.00716.86
7.4.160.0100.00916.54
7.4.150.0120.00417.40
7.4.140.0150.00317.86
7.4.130.0060.01116.78
7.4.120.0070.01016.84
7.4.110.0000.01716.77
7.4.100.0110.01016.57
7.4.90.0120.00616.71
7.4.80.0060.01619.39
7.4.70.0110.00716.74
7.4.60.0030.01316.63
7.4.50.0040.00416.65
7.4.40.0070.00722.77
7.4.30.0140.00416.65
7.4.00.0070.01115.37
7.3.330.0030.00213.55
7.3.320.0000.00613.46
7.3.310.0030.00316.38
7.3.300.0000.00616.58
7.3.290.0060.00916.56
7.3.280.0100.00716.57
7.3.270.0100.01017.40
7.3.260.0130.00716.59
7.3.250.0110.01016.62
7.3.240.0130.00316.81
7.3.230.0110.00616.50
7.3.210.0040.01316.91
7.3.200.0070.01019.39
7.3.190.0070.01316.72
7.3.180.0100.00716.72
7.3.170.0130.00416.72
7.3.160.0160.00616.75
7.3.120.0070.01014.90
7.3.10.0000.01116.61
7.3.00.0160.00316.66
7.2.330.0130.01016.87
7.2.320.0100.01016.81
7.2.310.0110.01116.80
7.2.300.0200.00016.88
7.2.290.0060.01116.95
7.2.130.0070.00716.94
7.2.120.0110.00716.76
7.2.110.0090.00317.26
7.2.100.0120.00316.83
7.2.90.0110.00716.92
7.2.80.0060.00616.86
7.2.70.0060.02217.14
7.2.60.0070.01517.11
7.2.50.0110.00816.78
7.2.40.0200.00317.06
7.2.30.0110.00717.13
7.2.20.0060.00617.19
7.2.10.0030.01017.09
7.2.00.0030.01018.29
7.1.250.0110.00415.70
7.1.100.0000.01118.60
7.1.70.0000.00817.49
7.1.60.0060.01919.82
7.1.50.0070.01717.27
7.1.00.0030.07322.34
7.0.200.0080.00316.61
7.0.140.0130.06722.00
7.0.60.0130.08319.87
7.0.50.0000.04317.88
7.0.40.0070.07320.14
7.0.30.0430.05720.09
7.0.20.0230.03320.24
7.0.10.0070.08720.21
7.0.00.0170.06720.34
5.6.280.0000.07720.90
5.6.210.0100.07720.51
5.6.200.0130.07018.27
5.6.190.0130.07720.47
5.6.180.0330.06720.34
5.6.170.0200.05320.71
5.6.160.0130.07320.71
5.6.150.0000.05718.15
5.6.140.0100.08018.15
5.6.130.0070.08318.24
5.6.120.0170.07321.03
5.6.110.0030.08721.09
5.6.100.0130.07721.00
5.6.90.0030.09020.96
5.6.80.0030.06720.39
5.6.70.4300.03720.39
5.5.350.0230.04320.35
5.5.340.0070.08018.09
5.5.330.0030.08320.38
5.5.320.0700.04020.31
5.5.310.0300.05020.18
5.5.300.0000.09018.05
5.5.290.0030.04018.08
5.5.280.0070.09320.81
5.5.270.0070.08020.89
5.5.260.0130.07320.96
5.5.250.0100.08020.70
5.5.240.0270.05720.20
5.4.450.0500.04019.33
5.4.440.0470.03319.39
5.4.430.0630.03719.16
5.4.420.0170.04719.27
5.4.410.0630.04318.96
5.4.400.0430.03319.22
5.4.390.0570.03019.17
5.4.380.0400.07718.47
5.4.370.0430.06318.70
5.4.360.0970.05318.78
5.4.350.0500.06718.77
5.4.340.0300.05718.74
5.4.320.0090.04012.52
5.4.310.0080.04112.51
5.4.300.0090.03512.52
5.4.290.0110.04112.51
5.4.280.0050.04012.40
5.4.270.0060.03612.41
5.4.260.0030.05319.03
5.4.250.0100.05318.77
5.4.240.0070.05318.93
5.4.230.0100.05018.99
5.4.220.0070.05719.03
5.4.210.0100.05018.79
5.4.200.0200.04719.00
5.4.190.0070.05318.79
5.4.180.0100.07718.95
5.4.170.0170.04318.74
5.4.160.0100.05018.98
5.4.150.0070.05318.98
5.4.140.0030.05716.58
5.4.130.0070.05016.61
5.4.120.0030.05716.39
5.4.110.0100.04716.38
5.4.100.0170.04016.50
5.4.90.0170.05716.37
5.4.80.0070.05716.33
5.4.70.0070.05016.63
5.4.60.0070.05016.34
5.4.50.0070.04716.31
5.4.40.0070.05716.44
5.4.30.0070.05016.39
5.4.20.0070.04716.34
5.4.10.0070.06316.47
5.4.00.0030.05015.83
5.3.290.0060.04312.80
5.3.280.0000.05714.68
5.3.270.0100.05014.51
5.3.260.0070.06714.83
5.3.250.0070.05014.69
5.3.240.0100.06714.77
5.3.230.0100.04714.67
5.3.220.0130.04314.74
5.3.210.0070.08014.57
5.3.200.0070.05314.56
5.3.190.0100.05014.59
5.3.180.0100.06014.55
5.3.170.0030.07314.47
5.3.160.0100.05014.66
5.3.150.0130.05014.65
5.3.140.0100.04314.66
5.3.130.0030.05714.71
5.3.120.0030.08314.54
5.3.110.0100.05014.68
5.3.100.0070.05014.13
5.3.90.0070.05713.92
5.3.80.0170.04313.85
5.3.70.0130.04314.11
5.3.60.0100.05714.17
5.3.50.0100.04313.94
5.3.40.0100.04714.02
5.3.30.0170.04014.00
5.3.20.0070.05013.67
5.3.10.0000.07313.73
5.3.00.0130.04313.61
5.2.170.0030.04311.32
5.2.160.0030.04011.15
5.2.150.0030.05711.23
5.2.140.0100.04011.23
5.2.130.0130.03311.09
5.2.120.0000.04311.09
5.2.110.0070.03711.17
5.2.100.0070.05311.09
5.2.90.0130.04011.18
5.2.80.0000.05011.16
5.2.70.0030.04711.09
5.2.60.0100.03710.96
5.2.50.0070.03711.11
5.2.40.0070.04010.98
5.2.30.0130.04310.94
5.2.20.0030.04011.02
5.2.10.0130.03010.81
5.2.00.0000.04310.79
5.1.60.0000.03710.07
5.1.50.0070.0379.98
5.1.40.0030.03710.03
5.1.30.0100.03710.34
5.1.20.0030.03710.44
5.1.10.0030.0409.91
5.1.00.0100.03010.12
5.0.50.0100.0308.56
5.0.40.0100.0208.41
5.0.30.0070.0408.28
5.0.20.0070.0338.25
5.0.10.0030.0278.42
5.0.00.0000.0508.23
4.4.90.0000.0376.68
4.4.80.0070.0176.68
4.4.70.0000.0236.68
4.4.60.0000.0236.68
4.4.50.0100.0136.68
4.4.40.0030.0406.68
4.4.30.0070.0206.68
4.4.20.0030.0306.68
4.4.10.0030.0306.68
4.4.00.0000.0476.68
4.3.110.0070.0176.68
4.3.100.0030.0206.68
4.3.90.0030.0206.68
4.3.80.0030.0336.68
4.3.70.0000.0236.68
4.3.60.0000.0336.68
4.3.50.0070.0176.68
4.3.40.0030.0476.68
4.3.30.0030.0206.68
4.3.20.0100.0206.68
4.3.10.0030.0206.68
4.3.00.0030.01713.41

preferences:
38.33 ms | 401 KiB | 5 Q