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, ''); } return implode($separator, $target); } $tests = [ '/foo/bar/./../baz' => null, '/foo/bar/./../../baz' => null, '/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.0100.01018.68
8.3.50.0080.00822.06
8.3.40.0140.00019.07
8.3.30.0150.00619.21
8.3.20.0000.00820.33
8.3.10.0040.00421.93
8.3.00.0000.00822.46
8.2.180.0120.00417.13
8.2.170.0060.00922.96
8.2.160.0110.00319.32
8.2.150.0000.00824.18
8.2.140.0090.00024.66
8.2.130.0030.00626.16
8.2.120.0000.00819.61
8.2.110.0030.00622.13
8.2.100.0080.00318.16
8.2.90.0030.00619.30
8.2.80.0040.00418.04
8.2.70.0000.00817.88
8.2.60.0040.00417.93
8.2.50.0040.00418.07
8.2.40.0040.00418.47
8.2.30.0000.00818.14
8.2.20.0050.00318.09
8.2.10.0030.00618.10
8.2.00.0030.00818.06
8.1.280.0100.01025.92
8.1.270.0050.00322.06
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00620.28
8.1.230.0110.00017.76
8.1.220.0080.00017.74
8.1.210.0080.00018.77
8.1.200.0030.00617.47
8.1.190.0060.00317.43
8.1.180.0090.00018.82
8.1.170.0040.00418.57
8.1.160.0040.00422.09
8.1.150.0000.00718.87
8.1.140.0120.00017.60
8.1.130.0000.00717.83
8.1.120.0040.00417.69
8.1.110.0090.00017.55
8.1.100.0040.00417.61
8.1.90.0000.00717.59
8.1.80.0050.00317.60
8.1.70.0000.00717.51
8.1.60.0080.00317.66
8.1.50.0030.00517.69
8.1.40.0040.00417.66
8.1.30.0000.00817.68
8.1.20.0040.00417.75
8.1.10.0030.00617.75
8.1.00.0030.00517.64
8.0.300.0060.00318.77
8.0.290.0000.00817.05
8.0.280.0030.00318.54
8.0.270.0070.00017.30
8.0.260.0060.00016.89
8.0.250.0030.00317.12
8.0.240.0080.00017.03
8.0.230.0070.00016.97
8.0.220.0030.00317.14
8.0.210.0070.00017.09
8.0.200.0070.00017.16
8.0.190.0000.00717.11
8.0.180.0040.00417.10
8.0.170.0050.00217.05
8.0.160.0000.00817.05
8.0.150.0080.00017.10
8.0.140.0040.00417.02
8.0.130.0030.00313.48
8.0.120.0000.00717.04
8.0.110.0000.00717.06
8.0.100.0070.00016.91
8.0.90.0000.00717.16
8.0.80.0130.00517.05
8.0.70.0000.00717.18
8.0.60.0000.00817.08
8.0.50.0000.00817.05
8.0.30.0100.00817.21
8.0.20.0140.00717.47
8.0.10.0030.00617.12
8.0.00.0150.00517.08
7.4.330.0050.00015.00
7.4.320.0070.00016.77
7.4.300.0000.00616.89
7.4.290.0000.00716.78
7.4.280.0070.00016.68
7.4.270.0030.00516.69
7.4.260.0070.00316.67
7.4.250.0070.00016.77
7.4.240.0040.00416.84
7.4.230.0030.00316.73
7.4.220.0190.00616.97
7.4.210.0090.00616.87
7.4.200.0030.00316.92
7.4.190.0070.00016.69
7.4.160.0130.00316.80
7.4.150.0130.00317.40
7.4.140.0100.00717.86
7.4.130.0140.00316.65
7.4.120.0130.00516.80
7.4.110.0090.00916.68
7.4.100.0060.01016.64
7.4.90.0030.01516.89
7.4.80.0080.00819.39
7.4.70.0100.00716.57
7.4.60.0060.01016.69
7.4.50.0000.00916.54
7.4.40.0030.01322.77
7.4.30.0070.01016.60
7.4.00.0060.00915.29
7.3.330.0020.00213.39
7.3.320.0030.00313.34
7.3.310.0070.00016.66
7.3.300.0000.00616.51
7.3.290.0040.01116.54
7.3.280.0080.00816.56
7.3.270.0090.00917.40
7.3.260.0090.00916.72
7.3.250.0100.01116.74
7.3.240.0090.00816.54
7.3.230.0080.00916.61
7.3.210.0110.00716.86
7.3.200.0100.00719.39
7.3.190.0180.00016.73
7.3.180.0090.00716.52
7.3.170.0100.00716.50
7.3.160.0180.00316.74
7.3.120.0110.00714.78
7.3.110.0090.00615.21
7.3.100.0060.00914.87
7.3.90.0060.00614.86
7.3.80.0070.00415.04
7.3.70.0030.01315.08
7.3.60.0070.01015.10
7.3.50.0030.01015.03
7.3.40.0090.00314.93
7.3.30.0090.00315.00
7.3.20.0090.00616.67
7.3.10.0040.00916.73
7.3.00.0070.00316.83
7.2.330.0140.01416.93
7.2.320.0090.01216.97
7.2.310.0090.00916.93
7.2.300.0030.01516.85
7.2.290.0110.00617.08
7.2.240.0080.00415.04
7.2.230.0060.00914.87
7.2.220.0090.00615.23
7.2.210.0120.00615.41
7.2.200.0030.00615.32
7.2.190.0060.00915.32
7.2.180.0030.01315.21
7.2.170.0090.00615.15
7.2.160.0060.01015.18
7.2.150.0030.01317.18
7.2.140.0000.01616.93
7.2.130.0050.01017.09
7.2.120.0120.00117.14
7.2.110.0090.00317.21
7.2.100.0000.01317.01
7.2.90.0070.00517.13
7.2.80.0050.00517.20
7.2.70.0070.00517.09
7.2.60.0030.01017.05
7.2.50.0070.00417.15
7.2.40.0030.00917.21
7.2.30.0070.00817.18
7.2.20.0020.00916.92
7.2.10.0050.00717.08
7.2.00.0020.00717.26
7.1.330.0070.00715.76
7.1.320.0060.01216.22
7.1.310.0080.00616.13
7.1.300.0040.00815.89
7.1.290.0080.00815.73
7.1.280.0090.00615.95
7.1.270.0090.00615.98
7.1.260.0040.01216.15
7.1.250.0050.00715.82
7.1.200.0030.00915.81
7.1.70.0000.00717.14
7.1.60.0090.01219.82
7.1.50.0100.01017.06
7.1.00.0070.07322.37
7.0.200.0050.00216.61
7.0.140.0070.07321.97
7.0.60.0100.07719.88
7.0.50.0100.04717.99
7.0.40.0000.07020.15
7.0.30.0300.05320.12
7.0.20.0300.04720.09
7.0.10.0200.06320.31
7.0.00.0030.04720.33
5.6.280.0070.07021.03
5.6.210.0030.05020.63
5.6.200.0070.06718.18
5.6.190.0100.06320.61
5.6.180.3570.03720.64
5.6.170.0430.07320.50
5.6.160.0100.05320.43
5.6.150.0100.08018.25
5.6.140.0030.08318.15
5.6.130.0100.08718.17
5.6.120.0070.05020.98
5.6.110.0100.07020.99
5.6.100.0100.04721.12
5.6.90.0100.08021.14
5.6.80.0100.06020.49
5.6.70.4330.04320.38
5.5.350.0030.06720.39
5.5.340.0030.05018.00
5.5.330.0070.05320.38
5.5.320.0300.05020.36
5.5.310.0230.05020.46
5.5.300.0100.03717.94
5.5.290.0200.06717.98
5.5.280.0070.06321.00
5.5.270.0030.05020.84
5.5.260.0130.04720.69
5.5.250.0030.06020.51
5.5.240.0100.08020.16
5.4.450.0530.05719.61
5.4.440.0570.05719.59
5.4.430.0070.05319.33
5.4.420.0530.05719.58
5.4.410.0230.05719.46
5.4.400.0730.00018.87
5.4.390.0770.00018.63
5.4.380.0430.03718.71
5.4.370.0630.06018.83
5.4.360.1170.04318.76
5.4.350.0770.04718.75
5.4.340.0870.05018.84
5.4.320.0090.03312.52
5.4.310.0060.05012.51
5.4.300.0070.03812.52
5.4.290.0070.04512.51
5.4.280.0080.04012.41
5.4.270.0060.03812.40
5.4.260.0170.07019.01
5.4.250.0030.05718.96
5.4.240.0100.05018.95
5.4.230.0170.04318.92
5.4.220.0000.06018.94
5.4.210.0170.04719.00
5.4.200.0100.04718.97
5.4.190.0170.04319.00
5.4.180.0170.04018.82
5.4.170.0030.05718.74
5.4.160.0130.04318.75
5.4.150.0070.05718.93
5.4.140.0100.04716.36
5.4.130.0070.05716.57
5.4.120.0070.05016.58
5.4.110.0170.04016.60
5.4.100.0070.05316.54
5.4.90.0130.05316.38
5.4.80.0000.05716.52
5.4.70.0100.05716.39
5.4.60.0030.06016.48
5.4.50.0130.04316.58
5.4.40.0030.05716.49
5.4.30.0170.04016.46
5.4.20.0130.06716.48
5.4.10.0130.04316.34
5.4.00.0070.05015.78
5.3.290.0090.04412.80
5.3.280.0130.04714.50
5.3.270.0100.05014.60
5.3.260.0070.05314.67
5.3.250.0100.04714.83
5.3.240.0070.05014.70
5.3.230.0070.05314.50
5.3.220.0100.05014.76
5.3.210.0100.05014.54
5.3.200.0130.04314.54
5.3.190.0170.04014.73
5.3.180.0100.04714.57
5.3.170.0100.04314.59
5.3.160.0030.05314.79
5.3.150.0100.05014.57
5.3.140.0130.04314.72
5.3.130.0100.05014.64
5.3.120.0030.05714.55
5.3.110.0030.07014.70
5.3.100.0030.05314.13
5.3.90.0030.05314.10
5.3.80.0100.05313.85
5.3.70.0070.05314.01
5.3.60.0100.05014.09
5.3.50.0130.04313.95
5.3.40.0170.04714.04
5.3.30.0130.04313.81
5.3.20.0100.06013.70
5.3.10.0070.05013.73
5.3.00.0030.05313.72
5.2.170.0100.03711.33
5.2.160.0030.04711.14
5.2.150.0100.04011.15
5.2.140.0200.03711.13
5.2.130.0030.04311.18
5.2.120.0030.04311.06
5.2.110.0070.04311.26
5.2.100.0100.03711.18
5.2.90.0030.04311.05
5.2.80.0130.03711.15
5.2.70.0100.04011.07
5.2.60.0000.05011.22
5.2.50.0000.04711.00
5.2.40.0070.03711.08
5.2.30.0100.04310.94
5.2.20.0030.04010.86
5.2.10.0100.03710.97
5.2.00.0030.04710.70
5.1.60.0130.04010.00
5.1.50.0070.03310.01
5.1.40.0130.0439.82
5.1.30.0000.03710.50
5.1.20.0070.03710.58
5.1.10.0030.0379.91
5.1.00.0100.03310.17
5.0.50.0070.0278.39
5.0.40.0070.0238.38
5.0.30.0070.0408.38
5.0.20.0000.0308.16
5.0.10.0100.0238.02
5.0.00.0100.0378.14
4.4.90.0030.0206.68
4.4.80.0000.0276.68
4.4.70.0000.0236.68
4.4.60.0030.0206.68
4.4.50.0030.0276.68
4.4.40.0070.0306.68
4.4.30.0130.0106.68
4.4.20.0070.0206.68
4.4.10.0030.0206.68
4.4.00.0070.0276.68
4.3.110.0000.0276.68
4.3.100.0070.0206.68
4.3.90.0000.0236.68
4.3.80.0030.0376.68
4.3.70.0030.0306.68
4.3.60.0030.0276.68
4.3.50.0070.0176.68
4.3.40.0000.0376.68
4.3.30.0000.0236.68
4.3.20.0030.0306.68
4.3.10.0000.0236.68
4.3.00.0100.0276.81

preferences:
53.1 ms | 401 KiB | 5 Q