Skip to content

Commit 4f0ca7b

Browse files
authored
Merge pull request #26 from kpp/bench_stream_fold
Add benches for stream::fold
2 parents ee371a7 + 1e8f41f commit 4f0ca7b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

benches/stream.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,38 @@ fn bench_stream_map(c: &mut Criterion) {
113113
});
114114
}
115115

116+
fn bench_stream_fold(c: &mut Criterion) {
117+
executor::block_on(async {
118+
let mut group = c.benchmark_group("stream::fold");
119+
120+
group.bench_function("futures", |b| {
121+
b.iter(async move || {
122+
use futures::stream::{iter, StreamExt};
123+
let stream = iter(1..=1000);
124+
let acc = stream.fold(0, async move |acc, x| acc + x);
125+
black_box(acc).await
126+
})
127+
});
128+
group.bench_function("async_combinators", |b| {
129+
b.iter(async move || {
130+
use futures::stream::iter;
131+
use futures_async_combinators::stream::fold;
132+
let stream = iter(1..=1000);
133+
let acc = fold(stream, 0, async move |acc, x| acc + x);
134+
black_box(acc).await
135+
})
136+
});
137+
138+
group.finish();
139+
});
140+
}
141+
116142
criterion_group!(
117143
benches,
118144
bench_stream_iter,
119145
bench_stream_next,
120146
bench_stream_collect,
121147
bench_stream_map,
148+
bench_stream_fold,
122149
);
123150
criterion_main!(benches);

0 commit comments

Comments
 (0)