3v4l.org

run code in 300+ PHP versions simultaneously
<?php function merger($array1, $array2) { $result = array_merge($array1, $array2); } function spreader($array1, $array2) { $result = [...$array1, ...$array2]; } function uniter($array1, $array2) { $result = $array1 + $array2; } $array1 = []; $key = 'a'; for ($i = 0; $i < 500; ++$i) { $array1[++$key] = $i; } $array2 = []; for ($i = 500; $i < 1000; ++$i) { $array2[++$key] = $i; } $runs = 1000; // array_merge in loop $t0 = microtime(true); for ($i = 0; $i < $runs; ++$i) { merger($array1, $array2); } $tMerge = microtime(true); echo "merge: " . ($tMerge - $t0) . PHP_EOL; // array_merge with spread operator $t1 = microtime(true); for ($i = 0; $i < $runs; ++$i) { spreader($array1, $array2); } $tSpread = microtime(true); echo "spread: " . ($tSpread - $t1) . PHP_EOL; // union operator $t2 = microtime(true); for ($i = 0; $i < $runs; ++$i) { uniter($array1, $array2); } $tUnion = microtime(true); echo "union: " . ($tUnion - $t2);

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.20.0070.02019.02
8.3.10.0070.01821.89
8.3.00.0070.02319.09
8.2.150.0060.02218.96
8.2.140.0000.02620.63
8.2.130.0060.02220.47
8.2.120.0070.02219.31
8.2.110.0070.02019.25
8.2.100.0030.02619.28
8.2.90.0040.02518.99
8.2.80.0060.02219.19
8.2.70.0070.02518.86
8.2.60.0070.02219.05
8.2.50.0030.02518.89
8.2.40.0030.02619.08
8.2.30.0030.02418.82
8.2.20.0060.02318.81
8.2.10.0070.02219.00
8.2.00.0100.01918.86
8.1.270.0070.02122.37
8.1.260.0070.02022.23
8.1.250.0030.02822.03
8.1.240.0090.01918.62
8.1.230.0060.02518.70
8.1.220.0100.02319.13
8.1.210.0090.01818.76
8.1.200.0040.02218.97
8.1.190.0100.02318.76
8.1.180.0070.02318.44
8.1.170.0100.01918.59
8.1.160.0070.02318.60
8.1.150.0000.02718.62
8.1.140.0030.02618.54
8.1.130.0070.02118.85
8.1.120.0090.01918.63
8.1.110.0100.01618.68
8.1.100.0080.01918.57
8.1.90.0060.02218.61
8.1.80.0070.02118.74
8.1.70.0070.02018.66
8.1.60.0100.01718.79
8.1.50.0070.02318.67
8.1.40.0030.02318.80
8.1.30.0040.02518.86
8.1.20.0070.02018.90
8.1.10.0060.02218.86
8.1.00.0070.02118.70

preferences:
30.01 ms | 403 KiB | 5 Q