hhpack / performance
Performance utility library for Hack
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Language:Hack
Requires
- hhvm: >=3.21.0
- hhvm/hhvm-autoload: ^1.5
Requires (Dev)
- facebook/fbexpect: ^2.1
- hhvm/hacktest: ^1.1
README
Basic usage
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; }
Benchmark
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());
Run the test
You can run the test with the following command.
composer install
composer test