3v4l.org

run code in 300+ PHP versions simultaneously
<?php function removeDotPathSegments($path) { if (strpos($path, '.') === false) { return $path; }  $inputBuffer = $path; $outputStack = [];  /** * 2. While the input buffer is not empty, loop as follows: */ while ($inputBuffer != '') { /** * A. If the input buffer begins with a prefix of "../" or "./", * then remove that prefix from the input buffer; otherwise, */ if (strpos($inputBuffer, "./") === 0) { $inputBuffer = substr($inputBuffer, 2); continue; } if (strpos($inputBuffer, "../") === 0) { $inputBuffer = substr($inputBuffer, 3); continue; }  /** * B. if the input buffer begins with a prefix of "/./" or "/.", * where "." is a complete path segment, then replace that * prefix with "/" in the input buffer; otherwise, */ if ($inputBuffer === "/.") { $outputStack[] = '/'; break; } if (substr($inputBuffer, 0, 3) === "/./") { $inputBuffer = substr($inputBuffer, 2); continue; }  /** * C. if the input buffer begins with a prefix of "/../" or "/..", * where ".." is a complete path segment, then replace that * prefix with "/" in the input buffer and remove the last * segment and its preceding "/" (if any) from the output * buffer; otherwise, */ if ($inputBuffer === "/..") { array_pop($outputStack); $outputStack[] = '/'; break; } if (substr($inputBuffer, 0, 4) === "/../") { array_pop($outputStack); $inputBuffer = substr($inputBuffer, 3); continue; }  /** * D. if the input buffer consists only of "." or "..", then remove * that from the input buffer; otherwise, */ if ($inputBuffer === '.' || $inputBuffer === '..') { break; }  /** * E. move the first path segment in the input buffer to the end of * the output buffer, including the initial "/" character (if * any) and any subsequent characters up to, but not including, * the next "/" character or the end of the input buffer. */ if (($slashPos = stripos($inputBuffer, '/', 1)) === false) { $outputStack[] = $inputBuffer; break; } else { $outputStack[] = substr($inputBuffer, 0, $slashPos); $inputBuffer = substr($inputBuffer, $slashPos); } }  return implode($outputStack);}  // --- Test --- $expectations = [ ['bar', '....//bar'], ['bar', './bar'], ['bar', '.././bar'], ['bar', '.././bar'], ['/foo/bar', '/foo/./bar'], ['/bar/', '/bar/./'], ['/', '/.'], ['/bar/', '/bar/.'], ['/bar', '/foo/../bar'], ['/', '/bar/../'], ['/', '/..'], ['/', '/bar/..'], ['/foo/', '/foo/bar/..'], ['', '.'], ['', '..'],];  foreach ($expectations as $struct) { list($expected, $input) = $struct; $result = removeDotPathSegments($input); echo ($expected === $result) ? "Success\n" : "Failure: {$expected} !== {$result}\n";}

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)
5.4.340.0070.03612.03
5.4.320.0050.03912.52
5.4.310.0110.03812.52
5.4.300.0060.04312.52
5.4.290.0070.04512.51
5.4.280.0090.04212.41
5.4.270.0020.04112.41
5.4.260.0050.04012.41
5.4.250.0050.04612.41
5.4.240.0100.04712.41
5.4.230.0050.04112.40
5.4.220.0040.04012.40
5.4.210.0080.03712.40
5.4.200.0070.05012.40
5.4.190.0140.05612.39
5.4.180.0090.03612.39
5.4.170.0120.03512.40
5.4.160.0100.06112.40
5.4.150.0110.04412.40
5.4.140.0060.04412.09
5.4.130.0100.06212.07
5.4.120.0070.04312.03
5.4.110.0050.03912.04
5.4.100.0060.03512.03
5.4.90.0090.03512.03
5.4.80.0020.04512.03
5.4.70.0070.03512.03
5.4.60.0040.03712.03
5.4.50.0070.03512.03
5.4.40.0050.03912.02
5.4.30.0050.03912.01
5.4.20.0070.03812.00
5.4.10.0040.04012.01
5.4.00.0100.03611.51
5.3.290.0070.04012.80
5.3.280.0110.05212.71
5.3.270.0110.05412.73
5.3.260.0110.05312.72
5.3.250.0100.04612.72
5.3.240.0050.05512.72
5.3.230.0070.04112.71
5.3.220.0070.03712.68
5.3.210.0030.04312.68
5.3.200.0090.03612.68
5.3.190.0050.04012.68
5.3.180.0070.03912.67
5.3.170.0090.03812.67
5.3.160.0090.03512.68
5.3.150.0040.04512.67
5.3.140.0050.04012.66
5.3.130.0070.04112.66
5.3.120.0080.03912.65
5.3.110.0110.04212.66
5.3.100.0050.04012.13
5.3.90.0080.03612.12
5.3.80.0070.04112.09
5.3.70.0040.04312.10
5.3.60.0070.03812.09
5.3.50.0050.03812.02
5.3.40.0090.03512.02
5.3.30.0070.03811.98
5.3.20.0090.04411.76
5.3.10.0060.04711.74
5.3.00.0100.05111.72
5.2.170.0070.0299.22
5.2.160.0030.0399.22
5.2.150.0050.0329.22
5.2.140.0040.0339.21
5.2.130.0050.0319.18
5.2.120.0060.0299.18
5.2.110.0070.0309.18
5.2.100.0080.0319.18
5.2.90.0040.0339.18
5.2.80.0070.0329.18
5.2.70.0080.0299.18
5.2.60.0030.0349.13
5.2.50.0120.0499.10
5.2.40.0020.0359.07
5.2.30.0090.0279.05
5.2.20.0050.0289.05
5.2.10.0070.0288.95
5.2.00.0050.0318.80
5.1.60.0020.0288.09
5.1.50.0020.0278.09
5.1.40.0040.0258.07
5.1.30.0050.0268.42
5.1.20.0040.0278.44
5.1.10.0050.0278.16
5.1.00.0040.0268.17
5.0.50.0030.0216.64
5.0.40.0050.0196.51
5.0.30.0030.0316.32
5.0.20.0060.0176.29
5.0.10.0040.0206.27
5.0.00.0060.0306.25
4.4.90.0090.0364.78
4.4.80.0040.0154.75
4.4.70.0020.0164.75
4.4.60.0020.0164.75
4.4.50.0010.0174.77
4.4.40.0040.0244.71
4.4.30.0080.0124.76
4.4.20.0020.0164.85
4.4.10.0030.0154.85
4.4.00.0030.0244.76
4.3.110.0020.0164.67
4.3.100.0010.0164.66
4.3.90.0010.0174.64
4.3.80.0020.0244.59
4.3.70.0020.0154.63
4.3.60.0020.0154.63
4.3.50.0000.0204.63
4.3.40.0020.0254.54
4.3.30.0020.0183.30
4.3.20.0030.0163.28
4.3.10.0020.0213.25
4.3.00.0130.0207.46

preferences:
143.88 ms | 1394 KiB | 7 Q