3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $data = array(); // Preparing test data array for ($i=0;$i<200;$i++) { for ($j=0;$j<500;$j++) { $data['some']['keys'][$i]['should not']['matter'][$j] = $i . ' - ' . $j; } if (memory_get_usage() > 50000000) break; } echo "Created $i elements\n"; function formatBytes($bytes, $precision = 2) { $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); return round($bytes / (1 << (10 * $pow)), $precision) . ' ' . $units[$pow]; } $start_usage = memory_get_usage(); $start_peak = memory_get_peak_usage(); $s = serialize($data); $usage = memory_get_usage(); $peak = memory_get_peak_usage(); echo "Serialize started at " . formatBytes($start_usage) . " usage and " . formatBytes($start_peak) . " peak\n"; echo "Peak usage increased by " . formatBytes($peak - $start_peak) . "\n"; echo "Actual usage increased by " . formatBytes($usage - $start_usage) . "\n"; echo "Resulting string size " . formatBytes(strlen($s)) . "\n";
Output for 7.2.0
Created 200 elements Serialize started at 8.14 MB usage and 8.15 MB peak Peak usage increased by 2.02 MB Actual usage increased by 2.02 MB Resulting string size 2.01 MB
Output for 7.0.0 - 7.1.7
Created 200 elements Serialize started at 8.11 MB usage and 8.11 MB peak Peak usage increased by 2.02 MB Actual usage increased by 2.02 MB Resulting string size 2.01 MB
Output for 5.4.0 - 5.6.28
Created 200 elements Serialize started at 17.18 MB usage and 17.19 MB peak Peak usage increased by 12.99 MB Actual usage increased by 2.01 MB Resulting string size 2.01 MB
Output for 5.3.2 - 5.3.29
Created 200 elements Serialize started at 17.58 MB usage and 17.58 MB peak Peak usage increased by 12.23 MB Actual usage increased by 2.01 MB Resulting string size 2.01 MB
Output for 5.3.0 - 5.3.1
Created 200 elements Serialize started at 17.58 MB usage and 17.58 MB peak Peak usage increased by 12.99 MB Actual usage increased by 2.02 MB Resulting string size 2.01 MB
Output for 5.2.10 - 5.2.17
Created 200 elements Serialize started at 16.3 MB usage and 16.3 MB peak Peak usage increased by 12.23 MB Actual usage increased by 2.01 MB Resulting string size 2.01 MB
Output for 5.2.2 - 5.2.3, 5.2.5 - 5.2.6, 5.2.8 - 5.2.9
Created 200 elements Serialize started at 16.3 MB usage and 16.3 MB peak Peak usage increased by 12.23 MB Actual usage increased by 2.14 MB Resulting string size 2.01 MB
Output for 5.2.4, 5.2.7
Created 200 elements Serialize started at 16.3 MB usage and 16.3 MB peak Peak usage increased by 12.99 MB Actual usage increased by 2.14 MB Resulting string size 2.01 MB
Output for 5.2.1
Created 200 elements Serialize started at 16.31 MB usage and 16.31 MB peak Peak usage increased by 14.15 MB Actual usage increased by 2.03 MB Resulting string size 2.01 MB
Output for 5.0.0 - 5.2.0
Fatal error: Call to undefined function memory_get_usage() in /in/rraln on line 9
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: memory_get_usage() in /in/rraln on line 9
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: memory_get_usage() in /in/rraln on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: memory_get_usage() in /in/rraln on line 9