functional-php / parallel
某些高阶函数的并行实现。
dev-master
2018-01-27 22:49 UTC
Requires
- php: >=7.0.0
Requires (Dev)
- atoum/atoum: *
Suggests
- krakjoe/pthreads-polyfill: If you are not sure pthreads are available, this polyfill will allow to run the code sequentially without any chance to your code.
This package is auto-updated.
Last update: 2024-09-21 19:45:21 UTC
README
使用 pthreads 库 对高阶函数 map
、filter
和 fold
进行并行实现。这样,计算将在多个线程之间分配,以便可以利用计算机的全部计算能力。
查看 pthreads 库的要求。如果您不确定是否满足要求,请安装 polyfill。
安装
composer require functional-php/parallel
基本用法
use FunctionalPHP\Parallel as p; p\map(4, function($i) { return $i + 2; }, [1, 2, 3, 4]); // will return [3, 4, 5, 6] p\filter(4, function($i) { return $i % 2 == 0; }, [1, 2, 3, 4]); // will return [2, 4] p\fold(4, function($a, $b) { return $a + $b; }, [1, 2, 3, 4], 0); // will return 10
测试
您可以使用以下命令运行库的测试套件
composer test
测试报告将在 reports
目录中可用。
贡献
欢迎任何形式的贡献
- 想法
- 拉取请求
- 问题