HacklangでのJITの検証とか、Vector、Setのパフォーマンスの計測がしたかったので作りました。
計測用のコードは下記のような感じになります。
namespace hhpack\performance\example; require_once __DIR__ . '/../vendor/autoload.php'; use hhpack\performance as bench; function main() : void { bench\sync()->times(15)->run(() ==> { $stack = Vector {}; for ($i = 0; $i < 200000; $i++) { $stack->add($i); } }); } main();
hhpack\performance\sync関数はベンチマークオブジェクトを返します。
後は、runメソッドで計測したいコードをlamdaで指定します。
非同期処理は、hhpack\performance\syncの代わりにhhpack\performance\asyncを使用します。
namespace hhpack\performance\example; require_once __DIR__ . '/../vendor/autoload.php'; use hhpack\performance as bench; async function main() : Awaitable<void> { await bench\async()->times(10)->run(async () ==> { // 非同期処理を書く }); } \HH\Asio\join(main());
結果のレポートは標準出力に出ますが、Markdownでも出せるようにするつもりです。
作ってみて、JITが有効になってる時と、無効になってる時での処理速度の違いなど、いろいろ計測できて良いです。