PHP code example of davidbehler / timer

1. Go to this page and download the library: Download davidbehler/timer 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/ */

    

davidbehler / timer example snippets

 php
use DavidBehler\Timer\Timer;

$timer = new Timer;
 php
$timer = new Timer(true, Timer::MICROTIME_TYPE);
 php
$timer = new Timer(false);
 php
$timer = new Timer(false);

$timer->start();
 php
$timer = new Timer;

$timer->pause();
 php
$timer = new Timer;

$timer->stop();
 php
$timer = new Timer;

$timer->pause();
$timer->start();
 php
$timer = new Timer;

$timer->restart();
 php
$timer = new Timer;

usleep(1000);

$timer->getDuration(); // returns 0.001 (in a perfect world, but of course timings aren't this perfect)
 php
$timer = new Timer;

usleep(500);

$timer->pause();

usleep(500);

$timer->getDuration(); // returns 0.0005 (in a perfect world, but of course timings aren't this perfect)
 php
$timer = new Timer;

usleep(500);

$timer->stop();

usleep(500);

$timer->getDuration(); // returns 0.0005 (in a perfect world, but of course timings aren't this perfect)
 php
$timer = new Timer;

sleep(1);

$timer->pause();

usleep(500);

$timer->start();

sleep(2);

$timer->pause();

$timer->getDuration(); // returns 3.005 (in a perfect world, but of course timings aren't this perfect)
 php
$timer->getReport();
 php
use DavidBehler\Timer\TimerCollection;

$timerCollection = new TimerCollection(Timer::MICROTIME_TYPE);
 php
$timerCollection->start('timer 1');

$timerCollection->getDuration('timer 1');
 php
$timerCollection->start('timer 1');
$timerCollection->start('timer 2');

$timerCollection->getDuration('timer 1');
$timerCollection->getDuration('timer 2');
// or
$timerCollection->start(array('timer 1', 'timer 2'));
$timerCollcetion->getDurations(array('timer 1', 'timer 2')); // returns an array of durations with timer labels as indeces
 php
$timerCollection->stop(array('timer 1', 'timer 2'));
$timerCollection->pause(array('timer 1', 'timer 2'));
$timerCollection->restart(array('timer 1', 'timer 2'));
 php
$timerCollection->getTimers(); // returns an array with all setup timers
$timerCollection->getTimers(true); // returns an array with all the setup timers' labels
 php
$timerCollection->getReport('timer 4');
 php
$timerCollection->getReports(array('timer 5', 'timer 6'));