PHP code example of sy / stopwatch
1. Go to this page and download the library: Download sy/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/ */
sy / stopwatch example snippets
use Sy\Stopwatch;
$stopwatch = new Stopwatch();
// Start timing
$stopwatch->start();
// Process to be timed
for ($i = 0; $i < 100000; $i++) {
// Do something...
}
// Stop timing
$stopwatch->stop();
// Retrieve time in seconds
$time = $stopwatch->getTime();
echo "Execution time: $time seconds";
use Sy\Stopwatch;
$stopwatch = new Stopwatch();
for ($i = 0; $i < 10; $i++) {
// Start timing process A
$stopwatch->start('A');
// Process A
for ($a = 0; $a < 1000; $a++) {
// Do something...
}
// Stop timing process A
$stopwatch->stop('A');
// Start timing process B
$stopwatch->start('B');
for ($b = 0; $b < 1000; $b++) {
// Do something...
}
// Stop timing process B
$stopwatch->stop('B');
}
// Retrieve time
$timeA = $stopwatch->getTime('A');
$timeB = $stopwatch->getTime('B');