ggomuk/g-bench
Composer 安装命令:
composer require ggomuk/g-bench
包简介
PHP Benchmark Component
关键字:
README 文档
README
G-Bench is a nice and light component for php benchmarking.
Installation
Add this in your composer.json
{
"require": {
"ggomuk/g-bench": "1.0.0"
}
}
Sample Usage
-
start(), stop()
require_once __DIR__ . '/vendor/autoload.php'; $gb = new \GBench\GBench(); $gb->start(); $temp = str_repeat('Hello World!', 10000); sleep(2); $gb->stop(); $gb->getDuration(); // 2003 (ms) $gb->getMemory(); // 2097152 (bytes) echo $gb; // 2.00 MB - 2003 ms
-
record()
require_once __DIR__ . '/vendor/autoload.php'; $gb = new \GBench\GBench(); $gb->start(); usleep(500000); $temp1 = str_repeat('Hello World!', 10000); // You can label records with the record method. // The benchmark does not stop as it only makes an intermediate record. $gb->record('step1'); usleep(500000); $temp2 = str_repeat('Hello World!', 100000); // You can also label records with the stop method. $gb->stop('step2'); // The details of the record can be seen below foreach ($gb->getRecords() as $record) { $record->getLabel(); // step1, step2 $record->getMemory(); // 2097152, 2097152 $record->getDuration(); // 505, 506 $record->getAccumulateMemory(); // 2097152, 4194304 echo $record; // Usage Memory : 2.00 MB | Accumulate Usage Memory : 2.00 MB | Record Duration : 505 ms -> step1 // Usage Memory : 2.00 MB | Accumulate Usage Memory : 4.00 MB | Record Duration : 506 ms -> step2 }
-
run()
require_once __DIR__ . '/vendor/autoload.php'; $gb = new \GBench\GBench(); $result = $gb->run(function () { usleep(500000); return str_repeat('Hello World!', 10000); }, 'sample_run'); $gb->getDuration() . "\n"; // 504 (ms) $gb->getMemory() . "\n"; // 2097152 (bytes) echo $gb . "\n"; // 2.00 MB - 504 ms
-
Handler
require_once __DIR__ . '/vendor/autoload.php'; $logger = new class extends \GBench\AbstractHandler { public function startAfter(\GBench\GBench $gbench) { echo 'good start'; } public function stopAfter(\GBench\GBench $gbench, \GBench\Record $record) { echo 'good stop'; } }; $gb = new \GBench\GBench($logger); $gb->start(); // good start $gb->stop(); // good stop
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-13