File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -113,11 +113,38 @@ fn bench_stream_map(c: &mut Criterion) {
113
113
} ) ;
114
114
}
115
115
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
+
116
142
criterion_group ! (
117
143
benches,
118
144
bench_stream_iter,
119
145
bench_stream_next,
120
146
bench_stream_collect,
121
147
bench_stream_map,
148
+ bench_stream_fold,
122
149
) ;
123
150
criterion_main ! ( benches) ;
You can’t perform that action at this time.
0 commit comments