lavoiesl/php-benchmark
最新稳定版本:v1.4
Composer 安装命令:
composer require lavoiesl/php-benchmark
包简介
Tool to compare different functions in PHP
README 文档
README
Tool to compare different functions in PHP
Install
Via Composer
composer require lavoiesl/php-benchmark
Usage
<?php $benchmark = new \Lavoiesl\PhpBenchmark\Benchmark(); $benchmark->add('md5', function() { return md5('test'); }); $benchmark->add('sha1', function() { return sha1('test'); }); $benchmark->run(); ?>
You can run $benchmark->run(false) to get results without any output
Notes about memory usage
Memory usage is monitored using register_tick_function but this does not do a good job at analysing small statements since the memory gets cleaned too quickly.
A simple trick is the return the value, the AbstractTest stores it temporarily.
To ensure proper tick analysis, use declare(ticks = 1); as early as possible.
See the memory test.
Output
Running tests 3000 times.
Testing 2/2 : sha1
Test Time Time (%) Memory Memory (%)
md5 1304 ms 0 B
sha1 2077 ms 59 % 0 B
Optimal test count guessing
By default, Benchmark will try to find an optimal number of runs so that each test takes a maximum of 2 seconds.
You can change this by forcing it with $benchmark->setCount($n) or change the time with $benchmark->guessCount($max_seconds).
Writing custom tests
You can extend AbstractTest and provide your own wrapper.
For an example of this, see the command test and the corresponding class.
A full example can be seen here: https://github.com/lavoiesl/php-cache-comparison
统计信息
- 总下载量: 49.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 97
- 点击次数: 1
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-08-12