3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Iterator; use Symfony\Component\Finder\Exception\AccessDeniedException; use Symfony\Component\Finder\SplFileInfo; /** * Extends the \RecursiveDirectoryIterator to support relative paths. * * @author Victor Berchet <victor@suumit.com> */ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator { /** * @var bool */ private $ignoreUnreadableDirs; /** * @var bool */ private $rewindable; // these 3 properties take part of the performance optimization to avoid redoing the same work in all iterations private $rootPath; private $subPath = false; private $directorySeparator = '/'; /** * Constructor. * * @param string $path * @param int $flags * @param bool $ignoreUnreadableDirs * * @throws \RuntimeException */ public function __construct($path, $flags, $ignoreUnreadableDirs = false) { if ($flags & (self::CURRENT_AS_PATHNAME | self::CURRENT_AS_SELF)) { throw new \RuntimeException('This iterator only support returning current as fileinfo.'); } parent::__construct($path, $flags); $this->ignoreUnreadableDirs = $ignoreUnreadableDirs; if ('/' !== DIRECTORY_SEPARATOR && !($flags & self::UNIX_PATHS)) { $this->directorySeparator = DIRECTORY_SEPARATOR; } } /** * Return an instance of SplFileInfo with support for relative paths. * * @return SplFileInfo File information */ public function current() { // the logic here avoids redoing the same work in all iterations if (null === $this->rootPath) { $this->rootPath = $this->getPath(); } if (false === $subPathname = $this->subPath) { $subPathname = $this->subPath = $this->getSubPath(); } if ('' !== $subPathname) { $subPathname .= $this->directorySeparator; } $subPathname .= $this->getFilename(); return new SplFileInfo($this->rootPath.$this->directorySeparator.$subPathname, $this->subPath, $subPathname); } /** * @return \RecursiveIterator * * @throws AccessDeniedException */ public function getChildren() { try { $children = parent::getChildren(); if ($children instanceof self) { // parent method will call the constructor with default arguments, so unreadable dirs won't be ignored anymore $children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs; // performance optimization to avoid redoing the same work in all children $children->rewindable = &$this->rewindable; $children->rootPath = $this->rootPath; } return $children; } catch (\UnexpectedValueException $e) { if ($this->ignoreUnreadableDirs) { // If directory is unreadable and finder is set to ignore it, a fake empty content is returned. return new \RecursiveArrayIterator(array()); } else { throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e); } } } /** * Do nothing for non rewindable stream. */ public function rewind() { if (false === $this->isRewindable()) { return; } // @see https://bugs.php.net/bug.php?id=49104 parent::next(); parent::rewind(); } /** * Checks if the stream is rewindable. * * @return bool true when the stream is rewindable, false otherwise */ public function isRewindable() { if (null !== $this->rewindable) { return $this->rewindable; } if (false !== $stream = @opendir($this->getPath())) { $infos = stream_get_meta_data($stream); closedir($stream); if ($infos['seekable']) { return $this->rewindable = true; } } return $this->rewindable = false; } } $r = RecursiveDirectoryIterator('./'); $r = new RecursiveIteratorIterator($r); var_dump(iterator_to_array());

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.0070.01116.75
8.3.50.0180.00321.13
8.3.40.0120.00418.87
8.3.30.0090.00618.71
8.3.20.0080.00020.07
8.3.10.0080.00021.77
8.3.00.0050.00319.68
8.2.180.0040.01116.38
8.2.170.0030.01222.96
8.2.160.0030.01020.52
8.2.150.0050.00324.18
8.2.140.0030.00524.66
8.2.130.0040.00426.16
8.2.120.0030.00617.50
8.2.110.0030.00721.04
8.2.100.0080.00417.63
8.2.90.0030.00519.22
8.2.80.0000.00817.97
8.2.70.0040.00417.63
8.2.60.0060.00317.80
8.2.50.0080.00019.04
8.2.40.0040.00421.10
8.2.30.0050.00218.02
8.2.20.0050.00317.71
8.2.10.0080.00017.91
8.2.00.0000.00717.95
8.1.280.0110.00425.92
8.1.270.0050.00320.42
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0070.00322.19
8.1.230.0120.00017.42
8.1.220.0000.00817.74
8.1.210.0000.00818.77
8.1.200.0030.00717.23
8.1.190.0080.00017.13
8.1.180.0040.00418.10
8.1.170.0050.00318.59
8.1.160.0040.00421.96
8.1.150.0050.00218.77
8.1.140.0050.00317.27
8.1.130.0030.00617.66
8.1.120.0040.00417.26
8.1.110.0000.00817.27
8.1.100.0000.00717.28
8.1.90.0040.00417.42
8.1.80.0000.00817.40
8.1.70.0000.00717.40
8.1.60.0040.00417.50
8.1.50.0060.00317.52
8.1.40.0040.00417.38
8.1.30.0050.00317.55
8.1.20.0040.00417.54
8.1.10.0040.00417.56
8.1.00.0060.00317.54
8.0.300.0000.00718.77
8.0.290.0050.00216.75
8.0.280.0000.00718.47
8.0.270.0000.00717.15
8.0.260.0000.00717.24
8.0.250.0000.00817.00
8.0.240.0050.00516.91
8.0.230.0100.00016.95
8.0.220.0030.00316.96
8.0.210.0050.00516.84
8.0.200.0000.00716.99
8.0.190.0040.00416.96
8.0.180.0000.00716.95
8.0.170.0000.00716.84
8.0.160.0040.00416.90
8.0.150.0000.00816.76
8.0.140.0040.00416.92
8.0.130.0030.00313.34
8.0.120.0070.00015.13
8.0.110.0060.00215.14
8.0.100.0040.00315.22
8.0.90.0000.00715.07
8.0.80.0030.01115.10
8.0.70.0020.00515.09
8.0.60.0000.00915.13
8.0.50.0010.00615.06
8.0.30.0100.00715.92
8.0.20.0090.00616.08
8.0.10.0060.00215.11
8.0.00.0100.00616.03
7.4.330.0020.00215.08
7.4.320.0000.00716.43
7.4.300.0000.00616.57
7.4.290.0040.00416.39
7.4.280.0040.00416.57
7.4.270.0080.00016.41
7.4.260.0040.00416.39
7.4.250.0000.00814.90
7.4.240.0030.00515.44
7.4.230.0050.00214.95
7.4.220.0070.00614.98
7.4.210.0040.00815.39
7.4.200.0030.00414.91
7.4.190.0030.00313.34
7.4.180.0040.00413.31
7.4.160.0070.00514.81
7.4.150.0120.00115.34
7.4.140.0090.00716.30
7.4.130.0120.00715.36
7.4.120.0090.00715.33
7.4.110.0090.00714.65
7.4.100.0070.00614.76
7.4.90.0090.00514.61
7.4.80.0120.00315.97
7.4.70.0030.01014.56
7.4.60.0090.00414.86
7.4.50.0060.00214.68
7.4.40.0030.00914.57
7.4.30.0070.00614.53
7.4.20.0030.00712.83
7.4.10.0000.01512.68
7.4.00.0050.01013.72
7.3.330.0000.00513.29
7.3.320.0060.00313.04
7.3.310.0040.00414.67
7.3.300.0020.00614.66
7.3.290.0060.00414.64
7.3.280.0080.00815.48
7.3.270.0060.01215.05
7.3.260.0090.00614.91
7.3.250.0090.00815.54
7.3.240.0110.00414.71
7.3.230.0110.00414.52
7.3.220.0140.00012.93
7.3.210.0080.00614.82
7.3.200.0120.00614.62
7.3.190.0090.00514.80
7.3.180.0070.00714.73
7.3.170.0070.00714.61
7.3.160.0060.00814.62
7.3.150.0080.00412.60
7.3.140.0060.00412.76
7.3.130.0080.00313.05
7.3.120.0100.00012.73
7.3.110.0090.00312.72
7.3.100.0120.00012.65
7.3.90.0050.00512.91
7.3.80.0080.00412.94
7.3.70.0120.00012.84
7.3.60.0060.00312.79
7.3.50.0050.00513.14
7.3.40.0050.00513.14
7.3.30.0090.00313.07
7.3.20.0100.00014.93
7.3.10.0080.00414.64
7.3.00.0100.00014.89
7.2.340.0100.00513.22
7.2.330.0080.00714.93
7.2.320.0060.01414.78
7.2.310.0070.00914.65
7.2.300.0110.00415.01
7.2.290.0050.01014.73
7.2.280.0070.00713.17
7.2.270.0060.00813.02
7.2.260.0090.00513.25
7.2.250.0130.00013.05
7.2.240.0130.00013.24
7.2.230.0100.00313.18
7.2.220.0130.00013.24
7.2.210.0120.00013.17
7.2.200.0080.00613.39
7.2.190.0150.00013.37
7.2.180.0080.00413.33
7.2.170.0050.00813.39
7.2.160.0120.00013.21
7.2.150.0110.00315.06
7.2.140.0060.00615.21
7.2.130.0080.00515.34
7.2.120.0060.00715.09
7.2.110.0080.00415.10
7.2.100.0130.00015.30
7.2.90.0150.00015.10
7.2.80.0120.00315.08
7.2.70.0060.00615.18
7.2.60.0090.00315.92
7.2.50.0070.00514.96
7.2.40.0100.00315.16
7.2.30.0110.00315.27
7.2.20.0110.00315.23
7.2.10.0100.00315.25
7.2.00.0070.00617.18
7.1.330.0120.00014.04
7.1.320.0140.00014.10
7.1.310.0120.00013.93
7.1.300.0080.00314.03
7.1.290.0070.00514.20
7.1.280.0090.00314.07
7.1.270.0070.00414.16
7.1.260.0120.00014.07
7.1.250.0120.00013.88
7.1.240.0110.00014.15
7.1.230.0070.00514.07
7.1.220.0120.00013.94
7.1.210.0040.00814.19
7.1.200.0080.00514.78
7.1.190.0120.00014.06
7.1.180.0120.00013.99
7.1.170.0060.00614.08
7.1.160.0080.00414.18
7.1.150.0120.00014.00
7.1.140.0080.00514.14
7.1.130.0120.00014.16
7.1.120.0130.00014.08
7.1.110.0120.00013.95
7.1.100.0060.00615.99
7.1.90.0040.00814.02
7.1.80.0000.01214.22
7.1.70.0060.00415.48
7.1.60.0090.00917.06
7.1.50.0070.00715.43
7.1.40.0120.00014.22
7.1.30.0070.00514.22
7.1.20.0070.00714.24
7.1.10.0080.00413.96
7.1.00.0050.04118.27
7.0.330.0090.00213.94
7.0.320.0110.00013.92
7.0.310.0120.00014.02
7.0.300.0110.00014.06
7.0.290.0060.00614.08
7.0.280.0120.00013.92
7.0.270.0090.00314.02
7.0.260.0120.00013.91
7.0.250.0040.00814.33
7.0.240.0120.00014.26
7.0.230.0070.00414.19
7.0.220.0040.00714.12
7.0.210.0120.00013.97
7.0.200.0080.00315.45
7.0.190.0110.00014.00
7.0.180.0040.00814.00
7.0.170.0120.00014.07
7.0.160.0120.00014.11
7.0.150.0090.00214.00
7.0.140.0100.00214.00
7.0.130.0080.00314.15
7.0.120.0130.00013.99
7.0.110.0080.00414.03
7.0.100.0110.00013.95
7.0.90.0060.00614.07
7.0.80.0090.00313.89
7.0.70.0080.00313.96
7.0.60.0060.03317.06
7.0.50.0050.03215.90
7.0.40.0110.04117.00
7.0.30.0220.03817.00
7.0.20.0120.02417.10
7.0.10.0120.02517.12
7.0.00.0050.03117.11
5.6.400.0040.00712.40
5.6.390.0100.00212.50
5.6.380.0080.00412.61
5.6.370.0080.00412.36
5.6.360.0100.00412.52
5.6.350.0110.00012.58
5.6.340.0070.00712.55
5.6.330.0030.01012.62
5.6.320.0080.00412.54
5.6.310.0080.00412.36
5.6.300.0110.00312.39
5.6.290.0120.00012.69
5.6.280.0040.03316.85
5.6.270.0070.00512.35
5.6.260.0060.00612.35
5.6.250.0040.00712.51
5.6.240.0070.00712.49
5.6.230.0090.00312.38
5.6.220.0090.00512.76
5.6.210.0070.04716.51
5.6.200.0060.02815.52
5.6.190.0120.04216.71
5.6.180.1690.02516.53
5.6.170.0220.03716.64
5.6.160.0080.03316.57
5.6.150.0110.03815.42
5.6.140.0090.04215.32
5.6.130.0040.04115.38
5.6.120.0050.04416.73
5.6.110.0100.04216.82
5.6.100.0140.04016.80
5.6.90.0060.03716.66
5.6.80.0120.03216.46
5.6.70.1590.01516.56
5.6.60.0060.00612.57
5.6.50.0080.00312.27
5.6.40.0110.00012.55
5.6.30.0050.00512.51
5.6.20.0050.00512.33
5.6.10.0080.00312.32
5.6.00.0060.00612.55
5.5.380.0080.00312.64
5.5.370.0080.00412.73
5.5.360.0110.00012.55
5.5.350.0040.04416.52
5.5.340.0080.04315.26
5.5.330.0040.03116.41
5.5.320.0190.02116.36
5.5.310.0150.03016.30
5.5.300.0040.04415.22
5.5.290.0040.02915.29
5.5.280.0090.04216.54
5.5.270.0110.04216.79
5.5.260.0070.04416.64
5.5.250.0020.03416.74
5.5.240.0140.01816.40
5.5.230.0110.00012.40
5.5.220.0050.00512.39
5.5.210.0050.00512.36
5.5.200.0070.00412.55
5.5.190.0100.00012.55
5.5.180.0080.00312.25
5.5.170.0050.00512.25
5.5.160.0100.00012.37
5.5.150.0070.00312.31
5.5.140.0080.00312.42
5.5.130.0080.00312.08
5.5.120.0040.00712.16
5.5.110.0070.00412.42
5.5.100.0000.01112.18
5.5.90.0110.00012.47
5.5.80.0000.01212.31
5.5.70.0110.00012.35
5.5.60.0070.00412.33
5.5.50.0120.00012.34
5.5.40.0110.00012.61
5.5.30.0080.00312.48
5.5.20.0080.00312.32
5.5.10.0080.00312.36
5.5.00.0050.00512.26
5.4.450.0420.03015.96
5.4.440.0380.03215.96
5.4.430.0400.03715.91
5.4.420.0350.03715.94
5.4.410.0470.03015.98
5.4.400.0520.03216.00
5.4.390.0420.03915.92
5.4.380.0430.03115.66
5.4.370.0390.02815.74
5.4.360.0420.02815.87
5.4.350.0390.03115.66
5.4.340.0340.03315.77
5.4.330.0110.00012.27
5.4.320.0390.02715.82
5.4.310.0290.03615.77
5.4.300.0390.03015.93
5.4.290.0540.02815.87
5.4.280.0320.03515.82
5.4.270.0450.03415.83
5.4.260.0460.02915.77
5.4.250.0510.03815.76
5.4.240.0480.03415.85
5.4.230.0460.03815.70
5.4.220.0390.03215.68
5.4.210.0520.03715.53
5.4.200.0470.03014.38
5.4.190.0370.02815.54
5.4.180.0210.03315.68
5.4.170.0360.03015.56
5.4.160.0390.02815.72
5.4.150.0340.03215.84
5.4.140.0050.03214.42
5.4.130.0150.02314.31
5.4.120.0360.02814.43
5.4.110.0280.02914.53
5.4.100.0260.03314.34
5.4.90.0070.04214.48
5.4.80.0410.02814.41
5.4.70.0300.03514.46
5.4.60.0320.02714.52
5.4.50.0090.02614.49
5.4.40.0080.04014.55
5.4.30.0290.03114.66
5.4.20.0290.02814.47
5.4.10.0230.03114.48
5.4.00.0360.02314.18

preferences:
76.47 ms | 401 KiB | 5 Q