3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { protected $path = '/tmp/directory'; public function createTestFiles () { $amount = 63; if (!is_dir($this->path)) { mkdir($this->path); } foreach (scandir($this->path) as $filename) { @unlink("{$this->path}/$filename"); } for ($num = 1; $num <= $amount; $num++) { fopen("{$this->path}/{$num}.txt", "a"); } } public function runTest() { echo 'get by foreach: ' . $this->getByForeach() . PHP_EOL; echo 'get by foreach with rewind: ' . $this->getByForeachWithRewind() . PHP_EOL; echo 'get by foreach after foreach: ' . $this->getByForeachAfterForeach() . PHP_EOL; echo 'get by loop: ' . $this->getByloop() . PHP_EOL; echo 'get by iterator_to_array: ' . $this->getByIteratorToArray() . PHP_EOL; echo 'get by iterator_to_array with rewind: ' . $this->getByIteratorToArrayWithRewind() . PHP_EOL; } public function getByForeach() { $directory = new RecursiveDirectoryIterator($this->path); $count = 0; foreach ($directory as $filename => $fileInfo) { $count++; } return $count; } public function getByForeachWithRewind() { $directory = new RecursiveDirectoryIterator($this->path); $count = 0; $directory->rewind(); foreach ($directory as $filename => $fileInfo) { $count++; } return $count; } public function getByForeachAfterForeach() { $directory = new RecursiveDirectoryIterator($this->path); $count = 0; foreach ($directory as $filename => $fileInfo) { // do nothing } foreach ($directory as $filename => $fileInfo) { $count++; } return $count; } public function getByLoop() { $directory = new RecursiveDirectoryIterator($this->path); $count = 0; while ($directory->valid()) { $count++; $directory->next(); } return $count; } public function getByIteratorToArray() { $directory = new RecursiveDirectoryIterator($this->path); return count(iterator_to_array($directory)); } public function getByIteratorToArrayWithRewind() { $directory = new RecursiveDirectoryIterator($this->path); $directory->rewind(); return count(iterator_to_array($directory)); } } $test = new Test(); $test->createTestFiles(); $test->runTest(); # comment so that 3v4l sees a change in the file

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.4.130.0180.00719.14
8.4.120.0120.01224.73
8.4.110.0150.01219.50
8.4.100.0190.00719.33
8.4.90.0170.00921.13
8.4.80.0050.00619.40
8.4.70.0150.01019.48
8.4.60.0190.00719.30
8.4.50.0140.01019.15
8.4.40.0180.00621.00
8.4.30.0070.01819.14
8.4.20.0170.00724.53
8.4.10.0070.00321.24
8.3.260.0140.01116.73
8.3.250.0150.00819.09
8.3.240.0170.00817.39
8.3.230.0180.00416.55
8.3.220.0070.00319.20
8.3.210.0070.00317.05
8.3.200.0140.00916.77
8.3.190.0150.00817.48
8.3.180.0150.00919.28
8.3.170.0130.01017.03
8.3.160.0180.00418.93
8.3.150.0130.01316.58
8.3.140.0070.01320.73
8.3.130.0100.01318.48
8.3.120.0000.01020.66
8.3.110.0070.00320.94
8.3.100.0080.00324.06
8.3.90.0060.00326.77
8.3.80.0090.00319.36
8.3.70.0160.00318.64
8.3.60.0230.00016.75
8.3.50.0120.00923.68
8.3.40.0130.01321.02
8.3.30.0090.00918.67
8.3.20.0060.00624.18
8.3.10.0060.00324.66
8.3.00.0090.00326.16
8.2.290.0120.01121.11
8.2.280.0150.00618.99
8.2.270.0180.00617.32
8.2.260.0160.00617.46
8.2.250.0070.00317.48
8.2.240.0040.00919.14
8.2.230.0060.00622.58
8.2.220.0100.00037.54
8.2.210.0070.00326.77
8.2.200.0040.00818.88
8.2.190.0080.01217.50
8.2.180.0090.00925.92
8.2.170.0090.00919.58
8.2.160.0200.00722.96
8.2.150.0030.00725.66
8.2.140.0070.00324.66
8.2.130.0000.00926.16
8.2.120.0030.00619.89
8.2.110.0060.00622.25
8.2.100.0070.00718.34
8.2.90.0030.00718.47
8.2.80.0030.00719.78
8.2.70.0210.00079.33
8.2.60.0170.00379.33
8.2.50.0140.00679.33
8.2.40.0110.00779.33
8.2.30.0090.00979.33
8.2.20.0160.00379.33
8.2.10.0090.00979.33
8.2.00.0130.00479.33
8.1.330.0140.01122.20
8.1.320.0190.00716.84
8.1.310.0130.00616.86
8.1.300.0030.00718.71
8.1.290.0110.00030.84
8.1.280.0070.01125.92
8.1.270.0100.00023.99
8.1.260.0030.00726.35
8.1.250.0080.00428.09
8.1.240.0110.00022.80
8.1.230.0100.00321.54
8.1.220.0060.00318.41
8.1.210.0030.00719.28
8.1.200.0160.00379.33
8.1.190.0090.00979.33
8.1.180.0200.00079.33
8.1.170.0090.00979.33
8.1.160.0060.01279.33
8.1.150.0180.00079.33
8.1.140.0100.01079.33
8.1.130.0130.00579.33
8.1.120.0070.01179.33
8.1.110.0090.00979.33
8.1.100.0180.00079.33
8.1.90.0110.00679.33
8.1.80.0140.00379.33
8.1.70.0150.00279.33
8.1.60.0140.00579.33
8.1.50.0150.00479.33
8.1.40.0140.00679.33
8.1.30.0110.00779.33
8.1.20.0150.00579.33
8.1.10.0140.00779.33
8.1.00.0110.00879.33
8.0.300.0000.00920.75
8.0.290.0110.00779.33
8.0.280.0090.00979.33
8.0.270.0090.00979.33
8.0.260.0090.00979.33
8.0.250.0160.00379.33
8.0.240.0120.00679.33
8.0.230.0210.00079.33
8.0.220.0150.00479.33
8.0.210.0180.00079.33
8.0.200.0120.00679.33
8.0.190.0150.00579.33
8.0.180.0200.00079.33
8.0.170.0000.01779.33
8.0.160.0120.00679.33
8.0.150.0120.00679.33
8.0.140.0150.00579.33
8.0.130.0130.00479.33
8.0.120.0120.00679.33
8.0.110.0120.00579.33
8.0.100.0130.00479.33
8.0.90.0130.00479.33
8.0.80.0050.01479.33
8.0.70.0160.00379.33
8.0.60.0140.00479.33
8.0.50.0110.00779.33
8.0.30.0130.00579.33
8.0.20.0070.01179.33
8.0.10.0140.00579.33
8.0.00.0090.00979.33
7.4.330.0130.00079.33
7.4.320.0160.00479.33
7.4.300.0180.00079.33
7.4.290.0150.00479.33
7.4.280.0060.01279.33
7.4.270.0110.00779.33
7.4.260.0110.00779.33
7.4.250.0210.00379.33
7.4.240.0150.00379.33
7.4.230.0110.00779.33
7.4.220.0070.01079.33
7.4.210.0070.01379.33
7.4.200.0180.00079.33
7.4.190.0140.00579.33
7.4.180.0140.00379.33
7.4.160.0160.00379.33
7.4.150.0090.00979.33
7.4.140.0130.00479.33
7.4.130.0040.01279.33
7.4.120.0150.00379.33
7.4.110.0140.00379.33
7.4.100.0080.00879.33
7.4.90.0080.00879.33
7.4.80.0120.00679.33
7.4.70.0140.00279.33
7.4.60.0130.00479.33
7.4.50.0170.00079.33
7.4.40.0100.00779.33
7.4.30.0110.00579.33
7.4.20.0160.00079.33
7.4.10.0120.00679.33
7.4.00.0120.00579.33
7.3.330.0100.00779.33
7.3.320.0090.00979.33
7.3.310.0120.00479.33
7.3.300.0140.00379.33
7.3.290.0140.00479.33
7.3.280.0060.01279.33
7.3.270.0100.00779.33
7.3.260.0080.01179.33
7.3.250.0090.00979.33
7.3.240.0110.01179.33
7.3.230.0100.00779.33
7.3.220.0170.00079.33
7.3.210.0110.00679.33
7.3.200.0110.00779.33
7.3.190.0130.00479.33
7.3.180.0130.00679.33
7.3.170.0140.00479.33
7.3.160.0140.00379.33
7.3.150.0150.00379.33
7.3.140.0090.00979.33
7.3.130.0200.00079.33
7.3.120.0180.00079.33
7.3.110.0130.00379.33
7.3.100.0130.00379.33
7.3.90.0120.00679.33
7.3.80.0040.01379.33
7.3.70.0110.00679.33
7.3.60.0120.00679.33
7.3.50.0160.00079.33
7.3.40.0080.00879.33
7.3.30.0080.00879.33
7.3.20.0120.00479.33
7.3.10.0120.00679.33
7.3.00.0080.00879.33
7.2.340.0160.00079.33
7.2.330.0170.00079.33
7.2.320.0060.01179.33
7.2.310.0150.00379.33
7.2.300.0130.00379.33
7.2.290.0140.00379.33
7.2.280.0120.00479.33
7.2.270.0090.00779.33
7.2.260.0130.00479.33
7.2.250.0130.00579.33
7.2.240.0170.00279.33
7.2.230.0120.00679.33
7.2.220.0100.00779.33
7.2.210.0100.00679.33
7.2.200.0190.00079.33
7.2.190.0120.00879.33
7.2.180.0090.00979.33
7.2.170.0140.00579.33
7.2.160.0060.01179.33
7.2.150.0180.00079.33
7.2.140.0130.00379.33
7.2.130.0120.00679.33
7.2.120.0130.00379.33
7.2.110.0120.00479.33
7.2.100.0040.01379.33
7.2.90.0080.00879.33
7.2.80.0130.00479.33
7.2.70.0160.00079.33
7.2.60.0130.00379.33
7.2.50.0090.00979.33
7.2.40.0120.00579.33
7.2.30.0140.00379.33
7.2.20.0110.00679.33
7.2.10.0120.00579.33
7.2.00.0110.00679.33

preferences:
29.53 ms | 403 KiB | 5 Q