3v4l.org

run code in 300+ PHP versions simultaneously
<?php function m() { $memory = round(memory_get_usage() / 1024 / 1024, 2); $frame = debug_backtrace(0, 1)[0]; $file = basename($frame['file']); $line = $frame['line']; printf("%s:%d | %sMb\n", $file, $line, $memory); } function gen(): \iterator { $data = str_repeat('x', 10 * 1024 * 1024); $i = 0; while ($data) { m(); yield $data; m(); unset($data); yield; m(); ++$i; // Simulate the API return nothing if ($i == 3) { $data = false; } else { $data = str_repeat('x', 10 * 1024 * 1024); } m(); } }; m(); foreach ($gen = gen() as $k => $v) { $gen->next(); m(); unset($k, $v); m(); } m();
Output for 7.3.0 - 7.3.19, 7.4.0 - 7.4.7
JHS6W:36 | 0.37Mb JHS6W:19 | 10.38Mb JHS6W:21 | 10.38Mb JHS6W:40 | 10.38Mb JHS6W:42 | 0.37Mb JHS6W:24 | 0.37Mb JHS6W:32 | 10.38Mb JHS6W:19 | 10.38Mb JHS6W:21 | 10.38Mb JHS6W:40 | 10.38Mb JHS6W:42 | 0.37Mb JHS6W:24 | 0.37Mb JHS6W:32 | 10.38Mb JHS6W:19 | 10.38Mb JHS6W:21 | 10.38Mb JHS6W:40 | 10.38Mb JHS6W:42 | 0.37Mb JHS6W:24 | 0.37Mb JHS6W:32 | 0.37Mb JHS6W:45 | 0.37Mb
Output for 7.2.0 - 7.2.31
JHS6W:36 | 0.37Mb JHS6W:19 | 10.37Mb JHS6W:21 | 10.37Mb JHS6W:40 | 10.37Mb JHS6W:42 | 0.37Mb JHS6W:24 | 0.37Mb JHS6W:32 | 10.37Mb JHS6W:19 | 10.37Mb JHS6W:21 | 10.37Mb JHS6W:40 | 10.37Mb JHS6W:42 | 0.37Mb JHS6W:24 | 0.37Mb JHS6W:32 | 10.37Mb JHS6W:19 | 10.37Mb JHS6W:21 | 10.37Mb JHS6W:40 | 10.37Mb JHS6W:42 | 0.37Mb JHS6W:24 | 0.37Mb JHS6W:32 | 0.37Mb JHS6W:45 | 0.37Mb

preferences:
35.11 ms | 411 KiB | 5 Q