3v4l.org

run code in 300+ PHP versions simultaneously
<?php function dirToArray1($dir) { $result = array(); $cdir = scandir($dir); foreach ($cdir as $key => $value) { if (!in_array($value,array(".",".."))) { if (is_dir($dir . DIRECTORY_SEPARATOR . $value)){ $result[$value] = dirToArray1($dir . DIRECTORY_SEPARATOR . $value); } else { $result[] = $value; } } } return $result; } function dirToArray2($dir) { $arr = []; $obj = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST); foreach ($obj as $info) { if (in_array($info->getFilename(), ['.', '..'])) continue; $path = $info->isDir() ? [$info->getFilename() => []] : [$info->getFilename()]; for ($depth = $obj->getDepth() - 1; $depth >= 0; $depth--) { $path = [$obj->getSubIterator($depth)->current()->getFilename() => $path]; } $arr = array_merge_recursive($arr, $path); } return $arr; } foreach (['1', '2'] as $k) { $t = "t$k"; $d = "d$k"; $$t = microtime(true); $func = "dirToArray$k"; $$d = $func("."); $$t = $$t - microtime(true); echo "$func needed $$t time\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)
8.0.121.8210.17236.43
8.0.111.8750.12736.42
8.0.101.8360.16736.45
8.0.91.8870.11336.20
8.0.81.8190.18334.49
8.0.71.7840.19832.70
8.0.61.8540.15432.90
8.0.51.8260.16933.11
8.0.31.8270.17332.74
8.0.21.8480.14235.59
8.0.11.8370.16336.44
8.0.01.8310.17035.78
7.4.251.7640.23231.50
7.4.241.8040.18532.70
7.4.231.8720.13733.36
7.4.221.8360.16633.07
7.4.211.8570.14333.07
7.4.201.8620.13635.78
7.4.191.8470.16036.36
7.4.181.8160.18632.97
7.4.161.7800.21231.79
7.4.151.8300.16132.86
7.4.141.8310.15532.61
7.4.131.8390.16733.28
7.4.121.8370.15936.17
7.4.111.8800.12036.09
7.4.101.8710.13035.75
7.4.91.8340.16332.57
7.4.81.8130.17932.74
7.4.71.8330.17032.82
7.4.61.8210.16932.49
7.4.51.8290.16933.80
7.4.41.8790.12336.25
7.4.31.8750.12736.02
7.4.21.8260.17734.61
7.4.11.7940.19932.77
7.4.01.8350.17032.86
7.3.311.8070.18933.09
7.3.301.7750.22633.39
7.2.00.0030.01019.50
7.1.70.0050.00217.27
7.1.60.0100.01419.33
7.1.50.0430.00716.98
7.1.00.0030.07722.41
7.0.200.0000.00716.50
7.0.140.0000.07722.15
7.0.60.0100.07021.82
7.0.50.0070.04017.88
7.0.40.0100.04720.18
7.0.30.0270.05320.21
7.0.20.0300.07720.25
7.0.10.0000.04320.07
7.0.00.0100.08320.25
5.6.280.0000.07721.01
5.6.210.0030.08020.48
5.6.200.0130.03718.18
5.6.190.0070.07020.42
5.6.180.0070.05020.62
5.6.170.0130.04020.55
5.6.160.0130.03720.55
5.6.150.0030.07318.16
5.6.140.0030.04718.24
5.6.130.0070.04018.18
5.6.120.0070.08320.91
5.6.110.0100.06021.06
5.6.100.0130.07720.98
5.6.90.0070.08320.99
5.6.80.0030.07720.46
5.5.350.3930.04320.42
5.5.340.0030.08017.94
5.5.330.0070.08320.57
5.5.320.0370.07020.35
5.5.310.0330.06020.38
5.5.300.0070.04017.94
5.5.290.0070.05717.98
5.5.280.0000.04320.91
5.5.270.0030.04320.66
5.5.260.0070.04320.74
5.5.250.0070.03720.63
5.5.240.0230.06020.20
5.4.450.3530.03319.28
5.4.440.3330.04319.17
5.4.430.3100.04319.19
5.4.420.3630.04019.47
5.4.410.3470.03319.36
5.4.400.3170.03719.17
5.4.390.3230.03318.98
5.4.380.3630.03719.22
5.4.370.3230.04019.31
5.4.360.3570.04319.14
5.4.350.3770.04319.09
5.4.340.3300.03019.32
5.4.320.3300.04019.00
5.4.310.3300.03319.20
5.4.300.3700.05019.24
5.4.290.3300.04019.04
5.4.280.3230.03718.84
5.4.270.3270.03719.20
5.4.260.3700.05319.21
5.4.250.3370.03718.86
5.4.240.2730.03719.23
5.4.230.3970.05019.16
5.4.220.3600.03719.14
5.4.210.2970.04019.18
5.4.200.2970.03319.13
5.4.190.3070.03019.21
5.4.180.3130.03719.13
5.4.170.3200.03318.93
5.4.160.3170.03718.97
5.4.150.3100.03318.84
5.4.140.3570.02316.44
5.4.130.3130.02716.57
5.4.120.3230.04016.71
5.4.110.2870.03316.61
5.4.100.3000.03016.35
5.4.90.3170.03716.41
5.4.80.3200.03316.29
5.4.70.2730.03016.58
5.4.60.3170.03316.57
5.4.50.3170.03316.44
5.4.40.3370.04316.43
5.4.30.3400.03716.56
5.4.20.3670.04016.43
5.4.10.3430.03716.53
5.4.00.2830.03715.84
5.3.290.3600.03714.68
5.3.280.3430.03314.52
5.3.270.3430.04014.66
5.3.260.3170.03714.53
5.3.250.3700.04714.52
5.3.240.3530.04014.52
5.3.230.3600.04014.75
5.3.220.3670.03014.54
5.3.210.3270.03714.54
5.3.200.2930.03714.68
5.3.190.3300.04014.58
5.3.180.3370.04014.64
5.3.170.3300.03714.57
5.3.160.3230.03714.62
5.3.150.3200.04014.54
5.3.140.3230.03714.46
5.3.130.3300.03014.56
5.3.120.3200.04014.52
5.3.110.3230.04014.56
5.3.100.3370.04014.11
5.3.90.3700.04014.17
5.3.80.2900.03714.17
5.3.70.1000.04713.95
5.3.60.0030.07713.91
5.3.50.0030.07013.87
5.3.40.0930.05713.87
5.3.30.3430.03313.96
5.3.20.3330.04013.77
5.3.10.3070.03713.89
5.3.00.3130.03313.79
5.2.170.2530.03311.38
5.2.160.2900.02711.21
5.2.150.2200.02311.23
5.2.140.2600.03011.23
5.2.130.3130.03311.19
5.2.120.2800.02711.12
5.2.110.2770.02711.00
5.2.100.2870.03011.08
5.2.90.2900.03011.11
5.2.80.2870.03011.21
5.2.70.2700.02011.32
5.2.60.2830.02711.06
5.2.50.2900.02711.17
5.2.40.2330.03310.92
5.2.30.2300.02710.88
5.2.20.2400.02710.93
5.2.10.2330.03010.96
5.2.00.2370.03310.65
5.1.60.2070.0279.93
5.1.50.2400.0279.92
5.1.40.2100.0239.88
5.1.30.2270.03010.42
5.1.20.2430.02710.33
5.1.10.2170.03010.16
5.1.00.2400.03010.16
5.0.50.0170.0238.47
5.0.40.0030.0438.41
5.0.30.0000.0338.14
5.0.20.0000.0408.09
5.0.10.0030.0278.33
5.0.00.0000.0408.06
4.4.90.0000.0176.90
4.4.80.0000.0176.90
4.4.70.0030.0376.90
4.4.60.0030.0136.90
4.4.50.0370.0236.90
4.4.40.1130.0236.90
4.4.30.1100.0136.90
4.4.20.1070.0136.90
4.4.10.1130.0176.90
4.4.00.1100.0236.90
4.3.110.1070.0176.90
4.3.100.1230.0206.90
4.3.90.1070.0136.90
4.3.80.1070.0236.90
4.3.70.1070.0136.90
4.3.60.1070.0176.90
4.3.50.1030.0176.90
4.3.40.1100.0206.90
4.3.30.0500.0176.90
4.3.20.0700.0236.90
4.3.10.0530.0206.90
4.3.00.0500.0176.90

preferences:
48.47 ms | 400 KiB | 5 Q