views:

45

answers:

3

I'm in the process of benchmarking my website.

class Home extends Controller {

    function Home() 
    {
        parent::Controller();
        $this->benchmark->mark('Constructor_start');

        $this->output->enable_profiler(TRUE);
        $this->load->library ('MasterPage');

        $this->benchmark->mark('Constructor_end');
    }

    function index() 
    {
        $this->benchmark->mark('Index_start');

        $this->masterpage->setMasterPage('master/home');
        $this->masterpage->addContent('home/index', 'page');
        $this->masterpage->show();

        $this->benchmark->mark('Index_end');
    }
}

These are the results:

Loading Time Base Classes: 0.0076
Constructor: 0.0007
Index: 0.0440
Controller Execution Time ( Home/ Index ): 0.4467
Total Execution Time: 0.4545`

I understand the following:

  • Loading Time Base Classes (0.0076)
  • Constructor (0.0007)
  • Index (0.0440)

But where is the rest of the time coming from?

A: 

I think the last line of your index function should be

$this->benchmark->mark('Index_end');

This typo might have caused the funny looking results.

Stephen Curran
No that's not the problem. Was just a typo in the question. Thanks for noticing though...
Ropstah
A: 

Codeigniter automatically benchmarks the total time from the request to the final output is sent to the browser (this is the Total Execution Time)

Also, when it is about to call the controller/method you specify (usually through the url) it marks the start of that and then when that method returns something or sends data to the output it ends that benchmark ( this is the Controller Execution Time ( Home/ Index ) you are seeing)

Tom Schlick
+1  A: 

I haven't done a lot of benchmarking of CI-powered sites, but 0.4545 doesn't seem very fast.

One thing that occurs under the umbrella of Controller Execution Time (but outside your custom defined benchmarks) is the autoloading of everything defined in the config/autoload.php file. If you're loading numerous libraries or models there, that would add to your Controller Execution Time without any immediately obvious reason.

Eric
No 0.4545 is NOT very fast, that's the main reason for me ending up here... I'm gonna try putting marks in the libraries I load...
Ropstah
Good catch, it seems to be a plugin. Thanks!
Ropstah