A simple object oriented profiling tool
$profiler = new \Dux\Profiler();
for($i=0; $i < $n; $i++) {
$profiler->start();
// do something that you want proifled
$profiler->end();
}
\Dux\Aggregate\Report::generate(
$profiler,
new \Dux\Aggregate\Mean()
)->renderAggregate();
// Outputs:
// Mean execution time: (mean)ms
When profiling sub-millisecond execution times, the overhead of the method calls can greatly impact your profiling results. To combat this, simply generate the microtime values and add them to the profiler after execution.
NOTE: Only use microtime()
, not microtime(true)
. Floating point numbers lose precision as they get larger. To deal with this, profile-dux makes use of the string representation of microtime which separates the millisecond offset from the Unix timestamp.
$profiler = new \Dux\Profiler();
for($i=0; $i < $n; $i++) {
$start = microtime();
// do something that you want proifled
$end = microtime();
$profiler->addProfile($start,$end);
}
Simply add zeroem/profile-dux
to your Composer requirements:
"require": {
"zeroem/profile-dux":"*"
}
and install your dependencies:
$> php composer.phar install