shmeeps / simple-timer
Simple interface for timing/benchmarking PHP applications
dev-master / 1.1.x-dev
2016-10-27 05:18 UTC
Requires
- php: >=5.0.0
This package is not auto-updated.
Last update: 2025-04-12 22:21:13 UTC
README
A simple timer used to track the execution time of PHP scripts
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")); } }