library simple-timer
Simple interface for timing/benchmarking PHP applications
shmeeps/simple-timer
Simple interface for timing/benchmarking PHP applications
- Thursday, October 27, 2016
- by shmeeps
- Repository
- 0 Watchers
- 0 Stars
- 3 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 1 Versions
- 0 % Grown
Simple Timer
A simple timer used to track the execution time of PHP scripts, (*1)
Usage
<?php
use Shmeeps\SimpleTimer\SimpleTimer;
class Foo
{
public function doSomething()
{
// ---- Single tracking
// Start the timer
SimpleTimer::start("formatLoop");
// Execute code
foreach ($this->objects as $object) {
$object->format();
}
// Stop the timer
SimpleTimer::stop("formatLoop");
// Output the total time spent in the loop
var_dump(SimpleTimer::getTotalTime("formatLoop"));
// ---- Multiple tracking
// Execute code
foreach ($this->objects as $object) {
SimpleTimer::start("fetchData");
$object->fetch();
SimpleTimer::stop("fetchData");
SimpleTimer::start("prepData");
$object->prep();
SimpleTimer::stop("prepData");
SimpleTimer::start("formatData");
$object->format();
SimpleTimer::stop("formatData");
}
// Output the total time fetching, the average time prepping, and both for formatting
var_dump(SimpleTimer::getTotalTime("fetchData"));
var_dump(SimpleTimer::getAverageTime("preData"));
var_dump(SimpleTimer::getRawTime("formatData"));
}
}