1. Go to this page and download the library: Download codon/profiler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
codon / profiler example snippets
$data = [/* ... */];
$profiler = new \Codon\Profiler();
$profiler->set('showOutput', false)
->add([
'name' => 'Count in loop', 'iterations' => 100,
'function' => function() use ($data, &$profiler) {
// This is the code to benchmark:
for($i = 0; $i <= count($data); $i++) {
echo $data[$i] . "\n";
}
}
])->run()->showResults();
$profiler->set($name, $value);
$test = [
'name' => 'Benchmark name',
'iterations' => # of times to run
'function' => closure of the test to run
];
$profiler->add($test);
$test = [
'name' => 'Sample',
'iterations' => 100
'function' => function() use (&$profiler) {
$profiler->checkpoint('Started!');
// some code
$profiler->startTimer('Subsection');
// Subsection of code
$profiler->endTimer('Subsection');
}
];
$profiler->add($test);
# You can chain these too
$profiler->add($test1)->add($test2);
$profiler->run();
class Test {
public $_data = [];
protected $_profiler;
public function __construct() {
$this->_profiler = new \Codon\Profiler();
}
public function runMethodProfiler() {
$this->_profiler->add([
'name' => 'testFunction', 'iterations' => 1,
'function' => function($class) use (&$this->_profiler) {
$class->testFunction($class->_data);
}
])->run($this);
}
public function testFunction($data = '') {
// Benchmark something in here
}
}