3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Benchmarking function with garbage collection disabled function benchmark($callback, $iterations = 100) { gc_disable(); // Disable garbage collection for clearer memory tracking $startTime = microtime(true); $startMemory = memory_get_peak_usage(); for ($i = 0; $i < $iterations; $i++) { $callback(); } $endTime = microtime(true); $endMemory = memory_get_peak_usage(); gc_enable(); // Re-enable garbage collection return [ 'time' => $endTime - $startTime, 'peak_memory' => $endMemory - $startMemory, ]; } // Test data - larger arrays to better see memory impact $baseArray = range(1, 1000); $newData = range(1001, 2000); // Method 1: Using array_merge in a loop $mergeArray = $baseArray; $mergeBenchmark = benchmark(function () use (&$mergeArray, $newData) { $tempArray = $mergeArray; // Clone array for memory comparison $mergeArray = array_merge($tempArray, $newData); }); // Method 2: Using array unpacking in a loop $unpackArray = $baseArray; $unpackBenchmark = benchmark(function () use (&$unpackArray, $newData) { $tempArray = $unpackArray; // Clone array for memory comparison $unpackArray = [...$tempArray, ...$newData]; }); // Display results echo "Array Merge:\n"; echo "Time: " . $mergeBenchmark['time'] . " seconds\n"; echo "Peak Memory: " . $mergeBenchmark['peak_memory'] . " bytes\n\n"; echo "Array Unpacking:\n"; echo "Time: " . $unpackBenchmark['time'] . " seconds\n"; echo "Peak Memory: " . $unpackBenchmark['peak_memory'] . " bytes\n";
Output for 8.3.13
Array Merge: Time: 0.057345867156982 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.023424863815308 seconds Peak Memory: 2101736 bytes
Output for 8.3.12
Array Merge: Time: 0.049566984176636 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.025577068328857 seconds Peak Memory: 2101736 bytes
Output for 8.3.11
Array Merge: Time: 0.024801015853882 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.024601936340332 seconds Peak Memory: 2101736 bytes
Output for 8.3.10
Array Merge: Time: 0.025130033493042 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.023287057876587 seconds Peak Memory: 2101736 bytes
Output for 8.3.9
Array Merge: Time: 0.024925947189331 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.024120092391968 seconds Peak Memory: 2101736 bytes
Output for 8.3.8
Array Merge: Time: 0.042020797729492 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.02730917930603 seconds Peak Memory: 2101736 bytes
Output for 8.3.7
Array Merge: Time: 0.026364088058472 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.024852991104126 seconds Peak Memory: 2101736 bytes
Output for 8.3.6
Array Merge: Time: 0.037142038345337 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.023299932479858 seconds Peak Memory: 2101736 bytes
Output for 8.3.5
Array Merge: Time: 0.061838150024414 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.049901962280273 seconds Peak Memory: 2101736 bytes
Output for 8.3.4
Array Merge: Time: 0.034754037857056 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.023500919342041 seconds Peak Memory: 2101736 bytes
Output for 8.3.3
Array Merge: Time: 0.024533987045288 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.023267030715942 seconds Peak Memory: 2101736 bytes
Output for 8.3.2
Array Merge: Time: 0.025000095367432 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.023370981216431 seconds Peak Memory: 2101736 bytes
Output for 8.3.1
Array Merge: Time: 0.063987970352173 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.025150060653687 seconds Peak Memory: 2101736 bytes
Output for 8.3.0
Array Merge: Time: 0.02504301071167 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.023688077926636 seconds Peak Memory: 2101736 bytes
Output for 8.2.25
Array Merge: Time: 0.024844884872437 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.040287971496582 seconds Peak Memory: 2101736 bytes
Output for 8.2.24
Array Merge: Time: 0.043604850769043 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.039489030838013 seconds Peak Memory: 2101736 bytes
Output for 8.2.23
Array Merge: Time: 0.027311086654663 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.040904998779297 seconds Peak Memory: 2101736 bytes
Output for 8.2.22
Array Merge: Time: 0.025068998336792 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.039479970932007 seconds Peak Memory: 2101736 bytes
Output for 8.2.21
Array Merge: Time: 0.026148080825806 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.041031122207642 seconds Peak Memory: 2101736 bytes
Output for 8.2.20
Array Merge: Time: 0.024946928024292 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.044043064117432 seconds Peak Memory: 2101736 bytes
Output for 8.2.19
Array Merge: Time: 0.024862051010132 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.043633937835693 seconds Peak Memory: 2101736 bytes
Output for 8.2.18
Array Merge: Time: 0.042393922805786 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.039487838745117 seconds Peak Memory: 2101736 bytes
Output for 8.2.17
Array Merge: Time: 0.05875301361084 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.07100510597229 seconds Peak Memory: 2101736 bytes
Output for 8.2.16
Array Merge: Time: 0.060102939605713 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.04216194152832 seconds Peak Memory: 2101736 bytes
Output for 8.2.15
Array Merge: Time: 0.054746866226196 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.040837049484253 seconds Peak Memory: 2101736 bytes
Output for 8.2.14
Array Merge: Time: 0.054632902145386 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.040719032287598 seconds Peak Memory: 2101736 bytes
Output for 8.2.13
Array Merge: Time: 0.04081392288208 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.040255069732666 seconds Peak Memory: 2101736 bytes
Output for 8.2.12
Array Merge: Time: 0.040993928909302 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.040781021118164 seconds Peak Memory: 2101736 bytes
Output for 8.2.11
Array Merge: Time: 0.024811983108521 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.043236970901489 seconds Peak Memory: 2101736 bytes
Output for 8.2.10
Array Merge: Time: 0.025650024414062 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.044676065444946 seconds Peak Memory: 2101736 bytes
Output for 8.2.9
Array Merge: Time: 0.03533411026001 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.040213108062744 seconds Peak Memory: 2101736 bytes
Output for 8.2.8
Array Merge: Time: 0.0279700756073 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.040317058563232 seconds Peak Memory: 2101736 bytes
Output for 8.2.7
Array Merge: Time: 0.025102853775024 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.039981126785278 seconds Peak Memory: 2101736 bytes
Output for 8.2.6
Array Merge: Time: 0.039433002471924 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.042466878890991 seconds Peak Memory: 2101736 bytes
Output for 8.2.5
Array Merge: Time: 0.027286052703857 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.040162086486816 seconds Peak Memory: 2101736 bytes
Output for 8.2.4
Array Merge: Time: 0.058609008789062 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.040970087051392 seconds Peak Memory: 2101736 bytes
Output for 8.2.3
Array Merge: Time: 0.024906873703003 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.041578054428101 seconds Peak Memory: 2101736 bytes
Output for 8.2.2
Array Merge: Time: 0.024882078170776 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.040259838104248 seconds Peak Memory: 2101736 bytes
Output for 8.2.1
Array Merge: Time: 0.025328159332275 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.041913986206055 seconds Peak Memory: 2101736 bytes
Output for 8.2.0
Array Merge: Time: 0.025392055511475 seconds Peak Memory: 4202616 bytes Array Unpacking: Time: 0.043225049972534 seconds Peak Memory: 2101736 bytes
Output for 8.1.30
Array Merge: Time: 0.06350302696228 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11415505409241 seconds Peak Memory: 4198888 bytes
Output for 8.1.29
Array Merge: Time: 0.095901966094971 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11256194114685 seconds Peak Memory: 4198888 bytes
Output for 8.1.28
Array Merge: Time: 0.062685012817383 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11333107948303 seconds Peak Memory: 4198888 bytes
Output for 8.1.27
Array Merge: Time: 0.062771081924438 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11355304718018 seconds Peak Memory: 4198888 bytes
Output for 8.1.26
Array Merge: Time: 0.064550161361694 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.1153450012207 seconds Peak Memory: 4198888 bytes
Output for 8.1.25
Array Merge: Time: 0.089020967483521 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11440300941467 seconds Peak Memory: 4198888 bytes
Output for 8.1.24
Array Merge: Time: 0.063034057617188 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11451005935669 seconds Peak Memory: 4198888 bytes
Output for 8.1.23
Array Merge: Time: 0.09037709236145 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11345720291138 seconds Peak Memory: 4198888 bytes
Output for 8.1.22
Array Merge: Time: 0.063206195831299 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11832594871521 seconds Peak Memory: 4198888 bytes
Output for 8.1.21
Array Merge: Time: 0.077824115753174 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.12053489685059 seconds Peak Memory: 4198888 bytes
Output for 8.1.20
Array Merge: Time: 0.063614845275879 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11389708518982 seconds Peak Memory: 4198888 bytes
Output for 8.1.19
Array Merge: Time: 0.085179090499878 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11887097358704 seconds Peak Memory: 4198888 bytes
Output for 8.1.18
Array Merge: Time: 0.089401006698608 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11412811279297 seconds Peak Memory: 4198888 bytes
Output for 8.1.17
Array Merge: Time: 0.08439302444458 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11816906929016 seconds Peak Memory: 4198888 bytes
Output for 8.1.16
Array Merge: Time: 0.063333034515381 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11527705192566 seconds Peak Memory: 4198888 bytes
Output for 8.1.15
Array Merge: Time: 0.061822891235352 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11176204681396 seconds Peak Memory: 4198888 bytes
Output for 8.1.14
Array Merge: Time: 0.062217950820923 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11453819274902 seconds Peak Memory: 4198888 bytes
Output for 8.1.13
Array Merge: Time: 0.078127861022949 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11555290222168 seconds Peak Memory: 4198888 bytes
Output for 8.1.12
Array Merge: Time: 0.063421010971069 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11467003822327 seconds Peak Memory: 4198888 bytes
Output for 8.1.11
Array Merge: Time: 0.063093900680542 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11319208145142 seconds Peak Memory: 4198888 bytes
Output for 8.1.10
Array Merge: Time: 0.063194036483765 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11658310890198 seconds Peak Memory: 4198888 bytes
Output for 8.1.9
Array Merge: Time: 0.078423976898193 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11328387260437 seconds Peak Memory: 4198888 bytes
Output for 8.1.8
Array Merge: Time: 0.062206029891968 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11406707763672 seconds Peak Memory: 4198888 bytes
Output for 8.1.7
Array Merge: Time: 0.080681085586548 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.1173529624939 seconds Peak Memory: 4198888 bytes
Output for 8.1.6
Array Merge: Time: 0.062979221343994 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11433601379395 seconds Peak Memory: 4198888 bytes
Output for 8.1.5
Array Merge: Time: 0.087001085281372 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.1133189201355 seconds Peak Memory: 4198888 bytes
Output for 8.1.4
Array Merge: Time: 0.063436031341553 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11647009849548 seconds Peak Memory: 4198888 bytes
Output for 8.1.3
Array Merge: Time: 0.062211990356445 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11663317680359 seconds Peak Memory: 4198888 bytes
Output for 8.1.2
Array Merge: Time: 0.062273025512695 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11493992805481 seconds Peak Memory: 4198888 bytes
Output for 8.1.1
Array Merge: Time: 0.098062038421631 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11843204498291 seconds Peak Memory: 4198888 bytes
Output for 8.1.0
Array Merge: Time: 0.06488299369812 seconds Peak Memory: 8396920 bytes Array Unpacking: Time: 0.11409187316895 seconds Peak Memory: 4198888 bytes

preferences:
43.64 ms | 515 KiB | 5 Q