PHP code example of 8ctopus / nano-timer
1. Go to this page and download the library: Download 8ctopus/nano-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/ */
8ctopus / nano-timer example snippets
use Oct8pus\NanoTimer\NanoTimer;
p(200000);
$timer->measure('usleep 200ms');
foreach (range(0, 50000) as $i) {
$a = $i * $i;
}
$timer->measure('range 0-50000');
echo $timer->table();
use Oct8pus\NanoTimer\NanoTimer;
// autoload and constructor time
$hrtime = hrtime(true);
utoload and constructor');
usleep(200000);
$timer->measure('200ms sleep');
sleep(1);
$timer->measure('1s sleep');
foreach (range(0, 50000) as $i) {
$a = $i * $i;
}
$timer->measure('pow range 0-50000');
echo $timer->table();
$timer = new NanoTimer();
$timer
->logSlowerThan(100)
->autoLog();
...
$variability1 = new NanoVariability();
for ($i = 1; $i < 6; ++$i) {
$ms = (1000 + rand(0, +200)) * 10;
usleep($ms);
$variability1->measure("lap {$i}");
}
echo $variability1->table(true) . "\n";
$v1 = new NanoVariability();
for ($i = 1; $i < 6; ++$i) {
usleep(500 + rand(0, 100));
$v1->measure("lap {$i}");
}
$v2 = new NanoVariability();
for ($i = 1; $i < 6; ++$i) {
usleep(500 + rand(0, 100));
$v2->measure("lap {$i}");
}
$compare = new Compare($v1, $v2);