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 = []; foreach ($allTheThings as $thing) { $ids[array_column($thing['stuff'], '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.2.90.0600.07014.72
7.2.80.0930.11914.89
7.2.70.0070.08015.20
7.2.60.0090.08015.25
7.2.50.0100.06615.02
7.2.40.0160.06814.82
7.2.30.0200.06215.02
7.2.20.0120.07115.02
7.2.10.0390.07715.12
7.2.00.0120.07714.82
7.1.210.1440.21814.09
7.1.200.0680.10413.87
7.1.190.0610.12613.70
7.1.180.0320.11513.85
7.1.170.0220.12013.74
7.1.160.0420.11213.76
7.1.150.0220.11014.09
7.1.140.0280.11613.96
7.1.130.0220.10013.87
7.1.120.0320.14813.66
7.0.310.0390.12113.71
7.0.300.0400.11813.60
7.0.290.0190.12213.55
7.0.280.0550.13913.56
7.0.270.0490.11913.64

preferences:
33.71 ms | 400 KiB | 5 Q