asad/benchmark

微PHP库,用于基准测试

1.0.5 2020-05-09 12:16 UTC

This package is auto-updated.

Last update: 2024-09-09 21:44:55 UTC


README

Latest Version on Packagist Build Status Quality Score Total Downloads License

此包仅适用于Laravel应用。如果您想在非Laravel应用中使用此包,请使用Ubench

要求

安装

您可以通过composer安装此包

composer require asad/benchmark

使用

use Asad\Bench\Benchmark;

$bench = new Benchmark();

$bench->start();

// Execute some code

$bench->end();

// Get elapsed time and memory
echo $bench->getTime(); // 156ms or 1.123s
echo $bench->getTime(true); // elapsed microtime in float
echo $bench->getTime(false, '%d%s'); // 156ms or 1s

echo $bench->getMemoryPeak(); // 152B or 90.00Kb or 15.23Mb
echo $bench->getMemoryPeak(true); // memory peak in bytes
echo $bench->getMemoryPeak(false, '%.3f%s'); // 152B or 90.152Kb or 15.234Mb

// Returns the memory usage at the end mark
echo $bench->getMemoryUsage(); // 152B or 90.00Kb or 15.23Mb

// Accepts a callable as the first parameter.  Any additional parameters will be passed to the callable.
$result = $bench->run(function ($x) {
    return $x;
}, 1);
echo $bench->getTime();

外观

如果您不想使用new关键字,请使用外观。

use Asad\Bench\BFacade;

BFacade::start();
// Execute some code
BFacade::end();

echo BFacade::getTime();
echo BFacade::getMemoryPeak(true);

测试

composer run test

变更日志

请参阅CHANGELOG以获取有关最近更改的更多信息。

贡献

请参阅CONTRIBUTING以获取详细信息。

致谢

此微框架由Devster开发。我是将此转换为Laravel包的人。

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件