3v4l.org

run code in 300+ PHP versions simultaneously
<?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.20
Memory used with static init: 2426568 Memory used with dynamic init: 9954008
Output for 5.6.0 - 5.6.28
Memory used with static init: 6614112 Memory used with dynamic init: 21878528
Output for 5.5.0 - 5.5.36
Memory used with static init: 6614048 Memory used with dynamic init: 21878488

preferences:
106.35 ms | 401 KiB | 110 Q