carloswph/sorter
Composer 安装命令:
composer require carloswph/sorter
包简介
Collection of sorting algorithms with annotations on procedures, history and functioning details.
README 文档
README
Collection of sorting algorithms implemented in PHP classes. Also, a benchmarking class for doing performance tests using any array and passing it through all available sorting algorithms. At this moment, this library can sort arrays in the following sorting algorithms:
- PHP sort()
- Quick Sorting
- Bubble Sorting
- Heap Sorting
- Gnome Sorting
- Shell Sorting
- Comb Sorting
- Insertion Sorting
- Merge Sorting
- Selection Sorting
- Matos-Goulart Simple Sorting (recently created by myself)
Matos-Goulart Simple Sorting Algorithm © 2021 by Carlos Artur C. S. Matos is licensed under Attribution 4.0 International .
All sorting algorithms can be applied to any array of integers using the respective static method. Also, using the class Benchmark() the developer can perform all sorting methods at once, and get a var_dump() of the benchmark times in seconds. Also, we compare all sort methods in the becnhmark with PHP's native sort() function, as reference.
Usage
require __DIR__ . '/vendor/autoload.php'; $matos = \Sorter\MatosGoulart::sort([2, 6, 78, 11, 23, 1, 4, 1902, 192]); /* Results in: array(9) { [0]=> int(1) [1]=> int(2) [2]=> int(4) [3]=> int(6) [4]=> int(11) [5]=> int(23) [6]=> int(78) [7]=> int(192) [8]=> int(1902) } */
Obviously, all other sorting methods will result in the same response array - as the main objective of this library is to realize benchmarking tests amongst all possible algorithms, rather than sorting numbers itself. All details on the algorithms and some pseudocode for implementations in other programming languages can be found on each class' docblock comments.
Benchmark
Also, this library has a Benchmark class, which can be used to subject an array to all sorting methods, and then return benchmark times for each of the sorting algorithms. As simple as follows:
use Sorter\Benchmark; require __DIR__ . '/vendor/autoload.php'; $ro = new Benchmark([2, 4, 1, 23, 32, 11, 45, 67, 5, 233455, 344 , 7, 24, 67, 1111111, 111, 34, 2344]); $ro->get(); /* RESULTS IN: array(8) { ["quick"]=> string(14) "0.127814000000" ["bubble"]=> string(14) "0.033583000000" ["heap"]=> string(14) "0.035445000000" ["gnome"]=> string(14) "0.015428000000" ["shell"]=> string(14) "0.012064000000" ["comb"]=> string(14) "0.000609000000" ["insertion"]=> string(14) "0.015089000000" ["matos_goulart"]=> string(14) "0.011882000000" } */
carloswph/sorter 适用场景与选型建议
carloswph/sorter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「benchmarking」 「Algorithm」 「sorting」 「algorithms」 「bubble sort」 「quick sort」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 carloswph/sorter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 carloswph/sorter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 carloswph/sorter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Syntactic sugar for PHP's sorting
The official Kohana benchmarking module
Simple class for logging time and memory usage of stuff
A simple helper class for Server Timing. Easily profile your code's execution time and send it to the client via the Server-Timing header.
Nestable table drag and drop sorting.
An ID Generator for PHP based on Snowflake Algorithm (Twitter announced).
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-only
- 更新时间: 2021-04-07