Codeigniter benchmarking, where are these ms coming from?

两盒软妹~` 提交于 2019-12-11 01:34:30

问题


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?


回答1:


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.




回答2:


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.




回答3:


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)



来源:https://stackoverflow.com/questions/2604064/codeigniter-benchmarking-where-are-these-ms-coming-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!