- memory_get_usage: documentation ( source)
<?php
class Service
{
public $class;
public function __construct($class)
{
$this->class = $class;
}
}
class Container
{
public $services = array();
}
$container = new Container();
$start = memory_get_usage();
for ($i = 0; $i < 1000; $i++) {
$container->services[] = array('Foo'.$i);
}
$delta = memory_get_usage() - $start;
echo 'Memory usage of 1000 service arrays: '.$delta, PHP_EOL;
$container = new Container();
$start = memory_get_usage();
for ($i = 0; $i < 1000; $i++) {
$container->services[] = new Service('Foo'.$i);
}
$delta = memory_get_usage() - $start;
echo 'Memory usage of 1000 service objects: '.$delta;