3v4l.org

run code in 300+ PHP versions simultaneously
<?php class LargeObject { protected $array; public function __construct() { $this->array = array_fill(0, 1000, 17); } public function getItemProcessor(): Closure { // Try with and without 'static' here return static function () { // do some processing unrelated to $this }; } } $start = microtime(true); $processors = []; for ($i = 0; $i < 1000; $i++) { $lo = new LargeObject(); $processors[] = $lo->getItemProcessor(); } $memory = memory_get_usage() >> 20; $time = (microtime(true) - $start) * 1000; printf("This took %dms and %dMB of memory\n", $time, $memory);
Output for 7.4.12, 7.4.15, 7.4.19, 7.4.21, 7.4.26, 7.4.32, 8.0.3 - 8.0.6, 8.0.21 - 8.0.22, 8.0.26 - 8.0.27, 8.0.29, 8.1.16, 8.1.27, 8.2.0 - 8.2.11, 8.2.16 - 8.2.22, 8.2.25 - 8.2.29, 8.3.2 - 8.3.3, 8.3.7, 8.3.9 - 8.3.14, 8.3.16 - 8.3.18, 8.3.21 - 8.3.22, 8.4.8 - 8.4.10, 8.5.0
This took 2ms and 0MB of memory
Output for 7.4.2 - 7.4.3, 7.4.5, 7.4.9, 7.4.18, 7.4.20, 8.0.12, 8.0.15 - 8.0.16, 8.1.0, 8.1.2, 8.1.9 - 8.1.10, 8.1.13 - 8.1.15, 8.1.17, 8.1.31, 8.2.12 - 8.2.15, 8.2.23, 8.3.4 - 8.3.6, 8.3.8, 8.3.19 - 8.3.20, 8.3.23 - 8.3.24, 8.4.1 - 8.4.2, 8.4.4, 8.4.6 - 8.4.7, 8.4.11
This took 1ms and 0MB of memory
Output for 8.0.2, 8.0.8 - 8.0.11, 8.0.24 - 8.0.25, 8.0.28, 8.3.0, 8.4.5
This took 5ms and 0MB of memory
Output for 7.4.0 - 7.4.1, 7.4.4, 7.4.8, 7.4.10 - 7.4.11, 7.4.13 - 7.4.14, 7.4.16, 7.4.22 - 7.4.25, 7.4.27 - 7.4.30, 7.4.33, 8.0.13 - 8.0.14, 8.0.17 - 8.0.20, 8.0.23, 8.1.1, 8.1.3 - 8.1.8, 8.1.11 - 8.1.12, 8.1.18 - 8.1.26, 8.1.28 - 8.1.30, 8.1.32 - 8.1.33, 8.2.24, 8.4.3
This took 3ms and 0MB of memory
Output for 7.4.6 - 7.4.7, 8.0.1, 8.0.7, 8.0.30, 8.3.15
This took 4ms and 0MB of memory
Output for 8.3.1
This took 7ms and 0MB of memory

preferences:
71.21 ms | 412 KiB | 5 Q