PHP code example of almasmurad / stopwatch

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

    

almasmurad / stopwatch example snippets


// create Stopwatch
$stopwatch = new Almasmurad\Stopwatch\Stopwatch();

// start measuring the first step
$stopwatch->start('code section #1');
//...

// start measuring the second step
$stopwatch->step('code section #2');
//...

// start measuring the third step
$stopwatch->step('code section #3');
//...

// finish measuring
$stopwatch->finish();

// output the report
$stopwatch->report();

$stopwatch = new Almasmurad\Stopwatch\Stopwatch();

//... (measured code)

$stopwatch->report();

$stopwatch->reportToFile(__DIR__.'/report.txt');

$stopwatch->reportToFileInAppendMode(__DIR__.'/report.txt');

// getting the report object
$report = $stopwatch->getReport();

// general indicators
$start   = $report->getStart()->getTimestamp();   // stopwatch start time
$finish  = $report->getFinish()->getTimestamp();  // stopwatch finish time
$elapsed = $report->getElapsed()->getSeconds();   // time of the entire stopwatch operation

// indicators of first code section 
$step1_start   = $report->getStepByIndex(0)->getStart()->getTimestamp();   
$step1_finish  = $report->getStepByIndex(0)->getFinish()->getTimestamp();  
$step1_elapsed = $report->getStep('code section #1')->getElapsed()->getSeconds();

// all of code sections
foreach ($report->getSteps() as $step){
    //...
}