<?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;
- Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0
- Memory used with static init: 2426568
Memory used with dynamic init: 2434760
- Output for 7.0.0 - 7.0.33
- Memory used with static init: 2426568
Memory used with dynamic init: 9954008
- Output for 5.6.0 - 5.6.38
- Memory used with static init: 6614080
Memory used with dynamic init: 21878576
- Output for 5.5.0 - 5.5.38
- Memory used with static init: 6614104
Memory used with dynamic init: 21878520
preferences:
60.99 ms | 410 KiB | 5 Q