Skip to content

Commit 91b7fa4

Browse files
committed
Benchmark mtdowling/transducers
1 parent 64caaf8 commit 91b7fa4

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

.idea/php.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/suspend.iml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"brainmaestro/composer-git-hooks": "^2.8",
2424
"phpunit/phpunit": "^9.5",
2525
"phpbench/phpbench": "^1.1",
26-
"pestphp/pest": "^1.20"
26+
"pestphp/pest": "^1.20",
27+
"mtdowling/transducers": "^0.3.0"
2728
},
2829
"autoload": {
2930
"psr-4": {

tests/Benchmarks/CollectionsBench.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
use Illuminate\Support\Collection;
88
use Illuminate\Support\Enumerable;
99
use Illuminate\Support\LazyCollection;
10+
use function transducers\comp as compose;
11+
use function transducers\filter;
12+
use function transducers\map;
13+
use function transducers\transduce;
1014

1115
class CollectionsBench
1216
{
@@ -65,6 +69,27 @@ public function bench_foreach_loop()
6569
$result->toArray();
6670
}
6771

72+
public function bench_mtdowling_transducers_package()
73+
{
74+
$xf = compose(
75+
filter(fn($number) => 0 === $number % 2),
76+
map(fn($number) => $number * 10),
77+
filter(fn($number) => $number > 100)
78+
);
79+
80+
$step = [
81+
'init' => function() {
82+
return new Collection();
83+
},
84+
'result' => 'Transducers\identity',
85+
'step' => function($result, $input) {
86+
return $result->push($input);
87+
},
88+
];
89+
90+
transduce($xf, $step, LazyCollection::range(1, 10000))->toArray();
91+
}
92+
6893
public function provideImplementations(): Generator
6994
{
7095
foreach ([Collection::class, LazyCollection::class] as $source) {

0 commit comments

Comments
 (0)