PHP code example of bnomei / kirby3-stopwatch

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

    

bnomei / kirby3-stopwatch example snippets


site()->stopwatch()->start('myevent');
sleep(1);
site()->stopwatch()->stop('myevent');
echo site()->stopwatch()->duration('myevent') . PHP_EOL; // float | int

$eventName = 'my event with laps';
$stopwatch = site()->stopwatch();
$stopwatch->start($eventName);
foreach ([random_int(100,500),random_int(100,500),random_int(100,500)] as $time) {
    usleep($time);
    $stopwatch->lap($eventName);
}
usleep(100);
$stopwatch->stop($eventName);
$totalDuration = $stopwatch->duration($eventName); // float | int
echo $totalDuration . PHP_EOL;
foreach ($stopwatch->getEvent($eventName)->getPeriods() as $period) {
    echo $period->getDuration() . PHP_EOL;  // float | int
}

$stopwatch = \Bnomei\Stopwatch::singleton();
$stopwatch->start('my event with laps');
sleep(1);
$stopwatch->stop('my event with laps');
$duration = $stopwatch->duration('my event with laps'); // float | int