- var_dump: documentation ( source)
- microtime: documentation ( source)
<?php
class Model
{
public function get() {}
}
class Foo {
protected $model;
public function __construct()
{
$this->model = new Model;
}
public function doSomethingGetModelOnce()
{
$model = $this->getModel();
for ($i = 0; $i < 1000000; $i++) {
$model->get();
}
}
public function doSomethingGetModelNTimes()
{
for ($i = 0; $i < 1000000; $i++) {
$this->getModel()->get();
}
}
protected function getModel()
{
return $this->model;
}
}
$foo = new Foo();
$time0 = microtime(true);
$foo->doSomethingGetModelOnce();
$time1 = microtime(true);
$foo->doSomethingGetModelNTimes();
$time2 = microtime(true);
var_dump(1000*($time1-$time0), 1000*($time2-$time1));