You can measure the time of easy processing.
use HHPack\Performance\PerformanceWatcher;
use HHPack\Performance\TimeWatcher;
use HHPack\Performance\MemoryWatcher;
use HHPack\Performance\Result\WatchedResult;
$watcher = PerformanceWatcher::fromItems([
Pair { 'time', new TimeWatcher() },
Pair { 'memory', new MemoryWatcher() }
]);
$watcher->start();
$watcher->stop();
$texts = $watcher->result()->mapWithKey(($key, $result) ==> {
return sprintf("%s: %s", $key, (string) $result->value());
})->values();
foreach ($texts as $text) {
echo $text, PHP_EOL;
}
use HHPack\Performance as bench;
function sync_benchmarker() : void
{
bench\sync()->times(10)->run(() ==> {
usleep(2000);
});
}
sync_benchmarker();
or
use HHPack\Performance as bench;
async function async_benchmarker_main() : Awaitable<void>
{
await bench\async()->times(10)->run(async () ==> {
await \HH\Asio\usleep(2000);
});
}
\HH\Asio\join(async_benchmarker_main());
You can run the test with the following command.
composer install
composer test