Spis treści
StatusDraft
TodoExpand on the default benchmarks (what do they measure?)

Benchmark Class

The benchmark class allows you to time your code. By default several benchmarks are run:

The results of the benchmarks will be outputted by the Profiler.

If a view is rendered {execution_time} and {memory_usage} can be used in the view to be replaced by the actual execution time and memory usage.

<box|Note:> Benchmark does not have to be loaded nor instanced. It is automatically loaded during the system setup and all its methods are static. </box>

Methods

start()

Benchmark::start($name) is used to start a new benchmark. Supply an unique name. Returns void.

Benchmark::start('benchmark1');

stop()

Benchmark::stop($name) is used to stop a benchmark. Supply the name given when the benchmark was started. Returns void.

Benchmark::stop('benchmark1');

get()

Benchmark::get($name, $decimals) is used to retrieve the results of a benchmark. Returns an array with the results: time is expressed in seconds, memory in bytes.

print_r(Benchmark::get('benchmark1')); 
// Output: Array ( [time] => 0.0078 [memory] => 472 )

The $decimal parameter is optional. Its default value is 4.

print_r(Benchmark::get('benchmark1', 6)); 
// Output: Array ( [time] => 0.007802 [memory] => 472 )

If you set the $name parameter to TRUE, all benchmarks will be returned.

print_r(Benchmark::get(TRUE, 3)); 
// Output: Array ( [477f51931a33e_total_execution] => Array ( [time] => 0.023 [memory] => 618940 ) [477f51931a33e_kohana_loading] => Array ( [time] => 0.012 [memory] => 369104 ) [477f51931a33e_environment_setup] => Array ( [time] => 0.002 [memory] => 54300 ) [477f51931a33e_system_initialization] => Array ( [time] => 0.003 [memory] => 65884 ) [477f51931a33e_controller_setup] => Array ( [time] => 0.008 [memory] => 177688 ) [477f51931a33e_controller_execution] => Array ( [time] => 0.000 [memory] => 4236 ) [benchmark1] => Array ( [time] => 0.008 [memory] => 472 ) )

<box|Note:> If for some reason the memory_get_usage() function is not available on your system, memory will be set to 0. </box>

Next : Event »