<?php
class Foo { private $foo = ["a" => 1, "b" => 2, "c" => 3, "d" => 4]; }
$i = 0;
$mem = memory_get_usage();
for ($i = 19999; --$i;) {
$s[] = new Foo;
}
$mem = memory_get_usage() - $mem;
echo "Memory used with static init: ", $mem, PHP_EOL;
class Bar { private $bar; function __construct() { $this->bar = ["a" => 1, "b" => 2, "c" => 3, "d" => 4]; } }
$mem = memory_get_usage();
for ($i = 19999; --$i;) {
$f[] = new Bar;
}
$mem = memory_get_usage() - $mem;
echo "Memory used with dynamic init: ", $mem, PHP_EOL;
preferences:
46.04 ms | 405 KiB | 5 Q