Class libraries


Benchmarking library for application run-time debugging.

You can set start point in code, run some staff, set end point and get time duration between start and end points. This will useful to debug DB queries and code which seems running slowly.

File: tokernel.framework/lib/benchmark.lib.php

Usage of benchmark

// Set start with id: 'this-moment' $this->lib->benchmark->start('this-moment'); // Do some staff, for example, run MySQL Query or loop, etc... // Set end $this->lib->benchmark->end('this-moment'); // Get elapsed time $duration = $this->lib->benchmark->elapsed('this-moment');

This example demonstrates how to set start time, do some staff, set end time and get the run-time duration.

Library methods

mixed float | bool between(string $owner_start, string $owner_end)

Return time duration between two points.

$this->lib->benchmark->start('this-moment-1'); // Do some staff $this->lib->benchmark->start('this-moment-2'); // Here also do some staff // Set end $this->lib->benchmark->end('this-moment-2'); $this->lib->benchmark->end('this-moment-1'); // Get elapsed time between two points. $duration = $this->lib->benchmark->between('this-moment-1', 'this-moment-2');

mixed float | bool elapsed(string $owner)

Get duration of point started before.

mixed float | bool end(string $owner)

Set end point. (stop the time calculation started before).

mixed array | bool get([string $owner])

Get benchmark value. Return total benchmark buffer if owner is not set.

bool set(string $owner, string $item, mixed $value)

Set additional data value to point. This can help us to get more information when debugging.

void start(string $owner)

Start point to benchmarking.