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";

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.130.0680.03623.18
8.3.120.0760.03122.70
8.3.110.0680.01022.89
8.3.100.0570.02022.76
8.3.90.0560.01623.13
8.3.80.0480.05223.14
8.3.70.0490.03223.11
8.3.60.0770.02122.93
8.3.50.1080.03623.18
8.3.40.0460.04624.21
8.3.30.0510.01823.98
8.3.20.0520.02724.13
8.3.10.0650.04423.90
8.3.00.0440.01624.02
8.2.250.0350.04823.52
8.2.240.0680.04123.50
8.2.230.0380.04823.11
8.2.220.0450.03823.13
8.2.210.0520.03523.36
8.2.200.0590.02923.35
8.2.190.0580.03823.25
8.2.180.0760.03623.12
8.2.170.0890.07024.59
8.2.160.0760.06324.59
8.2.150.0880.04424.46
8.2.140.0870.04224.21
8.2.130.0940.03924.36
8.2.120.0850.03024.54
8.2.110.0440.04124.46
8.2.100.0720.03324.56
8.2.90.0680.04224.57
8.2.80.0500.03724.31
8.2.70.0530.03224.40
8.2.60.0750.04224.45
8.2.50.0390.05224.38
8.2.40.0600.06324.38
8.2.30.0520.03124.34
8.2.20.0430.04024.36
8.2.10.0450.03924.40
8.2.00.0490.04224.40
8.1.300.1530.04928.53
8.1.290.1760.05728.67
8.1.280.1460.05828.81
8.1.270.1300.06329.74
8.1.260.1380.05730.21
8.1.250.1870.05030.08
8.1.240.1480.04530.00
8.1.230.1590.06629.79
8.1.220.1670.03030.05
8.1.210.1430.08629.91
8.1.200.1650.03029.88
8.1.190.1810.05329.90
8.1.180.1670.07029.53
8.1.170.1700.06329.81
8.1.160.1350.06129.70
8.1.150.1420.04629.85
8.1.140.1330.05829.87
8.1.130.1700.05429.61
8.1.120.1460.05429.77
8.1.110.1400.05129.92
8.1.100.1450.04930.04
8.1.90.1520.06929.90
8.1.80.1350.05629.91
8.1.70.1830.04529.98
8.1.60.1400.05430.00
8.1.50.1830.05029.86
8.1.40.1720.02430.16
8.1.30.1260.07029.94
8.1.20.1660.04229.83
8.1.10.1690.07329.83
8.1.00.1550.04029.95

preferences:
26.34 ms | 403 KiB | 5 Q