{elapsed_time} & {memory_usage} pseudo-variable in CodeIgniter

拈花ヽ惹草 提交于 2021-02-10 23:19:59

问题


Could anyone explain {elapsed_time} & {memory_usage} pseudo-variables in CodeIgniter? What template is this referring to?

In Benchmark.php

/**
 * Memory Usage
 *
 * This function returns the {memory_usage} pseudo-variable.
 * This permits it to be put it anywhere in a template
 * without the memory being calculated until the end.
 * The output class will swap the real value for this variable.
 *
 * @access  public
 * @return  string
 */
function memory_usage()
{
    return '{memory_usage}';
}

Thanks


回答1:


Those variables are from the Benchmarking class.

Quote from the official doc :

{elapsed_time}

display the total elapsed time from the moment CodeIgniter starts to the moment the final output is sent to the browser

{memory_usage}

The consumption will reflect the total memory used by the entire app

See how it works here : http://www.codeigniter.com/user_guide/libraries/benchmark.html

One use of this class is checking blocks of code :

public function myfunction()
{
    //Stuff here

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

    //Stuff suspected to be slow

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

    echo $this->benchmark->elapsed_time('start', 'end');
}


来源:https://stackoverflow.com/questions/28649101/elapsed-time-memory-usage-pseudo-variable-in-codeigniter

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