2017 © Pedro Peláez
 

library simple-timer

Simple interface for timing/benchmarking PHP applications

image

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

The README.md

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"));
    }
}

The Versions

27/10 2016

dev-master

9999999-dev https://github.com/shmeeps/simple-timer

Simple interface for timing/benchmarking PHP applications

  Sources   Download

MIT

The Requires

  • php >=5.0.0

 

timer