3v4l.org

run code in 300+ PHP versions simultaneously
<?php $allTheThings = [ ['stuff' => [ ['id' => 42], ]], ['stuff' => [ ['id' => 'never'], ]], ['stuff' => [ ['id' => 'gonna'], ]], ['stuff' => [ ['id' => 'give'], ]], ['stuff' => [ ['id' => 'you'], ]], ['stuff' => [ ['id' => 'up'], ]], ['stuff' => [ ['id' => 42], ]], ['stuff' => [ ['id' => 'never'], ]], ['stuff' => [ ['id' => 'gonna'], ]], ['stuff' => [ ['id' => 'let'], ]], ['stuff' => [ ['id' => 'you'], ]], ['stuff' => [ ['id' => 'down'], ]], ['stuff' => [ ['id' => 42], ]], ]; $t = microtime(true); for ($i = 0; $i < 10000; $i++) { // original code $ids = []; foreach ($allTheThings as $thing) { $ids = array_merge($ids, array_column($thing['stuff'], 'id')); } $ids = array_unique($ids); } $t = microtime(true) - $t; var_export($ids); echo 'original: '.$t."\n"; $t = microtime(true); for ($i = 0; $i < 10000; $i++) { // improved code $allTheIds = array_map(function ($thing) { return array_column($thing['stuff'], 'id'); }, $allTheThings); $ids = array_unique(array_merge(...$allTheIds)); } $t = microtime(true) - $t; var_export($ids); echo 'improved: '.$t."\n"; $t = microtime(true); for ($i = 0; $i < 10000; $i++) { // new code $ids = array(); foreach ($allTheThings as $thing) { $idstemp = array_column($thing['stuff'], 'id'); foreach ($idstemp as $id) { $ids[$id] = "1"; } } } $t = microtime(true) - $t; var_export($ids); echo 'new: '.$t."\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)
7.4.00.0070.08615.15
7.3.120.0030.15615.07
7.3.110.0030.16315.05
7.3.100.0070.10514.81
7.3.90.0030.09714.79
7.3.80.0030.09515.23
7.3.70.0100.11314.90
7.3.60.0070.10714.99
7.3.50.0070.10714.89
7.3.40.0030.09614.59
7.3.30.0100.13714.85
7.3.20.0000.10316.58
7.3.10.0100.08216.68
7.3.00.0030.09316.59
7.2.250.0130.13815.34
7.2.240.0100.15815.33
7.2.230.0100.10815.36
7.2.220.0070.11315.27
7.2.210.0000.12615.08
7.2.200.0070.11115.26
7.2.190.0130.10115.05
7.2.180.0030.11614.80
7.2.170.0030.12515.17
7.2.110.0180.09516.51
7.2.100.0300.08316.66
7.2.90.0330.09416.82
7.2.80.0220.09816.84
7.2.70.0220.07717.14
7.2.60.0150.08316.89
7.2.50.0160.08016.91
7.2.40.0140.09316.98
7.2.30.0310.09117.02
7.2.20.0260.07616.61
7.2.10.0420.07716.89
7.2.00.0220.08518.16
7.1.330.0030.20515.90
7.1.320.0000.20915.95
7.1.310.0030.22815.92
7.1.300.0000.20315.60
7.1.290.0030.26815.82
7.1.280.0130.20015.74
7.1.270.0100.20115.89
7.1.260.0030.20115.75
7.1.230.0200.11415.75
7.1.220.0170.12615.81
7.1.210.0230.11515.68
7.1.200.0220.14815.93
7.1.190.0230.11615.86
7.1.180.0220.12515.72
7.1.170.0230.13815.73
7.1.160.0160.11615.59
7.1.150.0070.12015.86
7.1.140.0280.11615.55
7.1.130.0180.11615.63
7.1.120.0320.12315.68
7.1.110.0170.11915.81
7.1.100.0100.11917.08
7.1.90.0170.11915.94
7.1.80.0280.11715.59
7.1.70.0150.14916.63
7.1.60.0240.16625.53
7.1.50.0250.15125.35
7.1.40.0230.13625.07
7.1.30.1150.15225.17
7.1.20.1300.14125.21
7.1.10.0070.18916.16
7.1.00.0150.20016.23
7.0.310.0110.14915.48
7.0.300.0160.12115.40
7.0.290.0270.13015.39
7.0.280.0190.13215.49
7.0.270.0380.11115.32
7.0.260.0260.11215.19
7.0.250.0170.11715.41
7.0.240.0200.11715.49
7.0.230.0500.12215.09
7.0.220.0110.12415.41
7.0.210.0150.16415.55
7.0.200.0270.16116.03
7.0.190.0100.16715.93
7.0.180.0120.16115.88
7.0.170.0180.15815.87
7.0.160.0080.15815.96
7.0.150.0080.18215.88
7.0.140.0120.17815.68
7.0.130.0130.17816.00
7.0.120.0130.14915.99
7.0.110.0160.21915.88
7.0.100.0240.17615.86
7.0.90.0150.15115.88
7.0.80.0070.17215.90
7.0.70.0150.14815.90
7.0.60.0110.18715.87
7.0.50.0100.16615.94
7.0.40.0110.18815.08
7.0.30.0070.19014.92
7.0.20.0030.16714.82
7.0.10.0160.21314.94
7.0.00.0100.17314.91
5.6.380.0100.27514.55

preferences:
40.03 ms | 401 KiB | 5 Q