smuuf/phpcb
Composer 安装命令:
composer require smuuf/phpcb
包简介
PHP Code Benchmark
README 文档
README
phpcb (php code benchmark)
phpcb is a very simple and very lightweight tool for speed benchmarking of various little pieces of PHP code, written in PHP, of course.
Why
phpcb is meant to be used in those situations when there are multiple ways of how to do something - and you know all will have the exact same result - but you just can't decide which would ultimately be the best (meaning "fastest") to use.
Requirements
- PHP 7.4+
- BCMath Arbitrary Precision Mathematics library for PHP; shouldn't be a problem, since it is commonly shipped with PHP itself.
Installation
composer require --dev smuuf/-hpcb
Usage
Write your microbenchmarks in a some file. For example mymicrobench.php (here placed in phpcb's root directory, so it's clear we rquire Composer's autoload file from correct place):
<?php require __DIR__ . '/../vendor/autoload.php'; $bench = new \Smuuf\Phpcb\PhpBenchmark; const COUNT = 100; $bench->addBench(function() { for ($i = 1; $i <= COUNT; $i++) {} }); $bench->addBench(function() { for ($i = COUNT; $i > 0; $i--) {} }); $bench->addBench(function() { for ($i = COUNT; $i--;) {} }); $bench->addBench(function() { for ($i = -COUNT; $i++;) {} }); $bench->run();
And then run it:
$ php ./mymicrobench.php
And observe results:
█ PHP Code Benchmark (phpcb) █ PHP 7.4.27 Engine used: Chaotic Engine Total time: 1.3220 sec Iterations: 1 000 000 ██ 2. Score: 100.00, 0.2660 sec ┌ │ $bench->addBench(function() { │ for ($i = COUNT; $i > 0; $i--) {} │ }); └ ██ 1. Score: 86.54, 0.3074 sec, 1.16x slower ┌ │ $bench->addBench(function() { │ for ($i = 1; $i <= COUNT; $i++) {} │ }); └ ██ 4. Score: 71.13, 0.3740 sec, 1.41x slower ┌ │ $bench->addBench(function() { │ for ($i = -COUNT; $i++;) {} │ }); └ ██ 3. Score: 71.02, 0.3746 sec, 1.41x slower ┌ │ $bench->addBench(function() { │ for ($i = COUNT; $i--;) {} │ }); └
smuuf/phpcb 适用场景与选型建议
smuuf/phpcb 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.43k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2017 年 06 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 smuuf/phpcb 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 smuuf/phpcb 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.43k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2017-06-23