File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 1
1
use criterion:: { black_box, criterion_group, criterion_main, Criterion } ;
2
2
use itertools:: free:: cloned;
3
3
use itertools:: Itertools ;
4
+ use itertools:: Position ;
4
5
use itertools:: { iproduct, EitherOrBoth } ;
5
6
6
7
use std:: cmp;
@@ -819,6 +820,22 @@ fn permutations_slice(c: &mut Criterion) {
819
820
} ) ;
820
821
}
821
822
823
+ fn with_position_fold ( c : & mut Criterion ) {
824
+ let v = black_box ( ( 0 ..10240 ) . collect_vec ( ) ) ;
825
+ c. bench_function ( "with_position fold" , move |b| {
826
+ b. iter ( || {
827
+ v. iter ( )
828
+ . with_position ( )
829
+ . fold ( 0 , |acc, ( pos, & item) | match pos {
830
+ Position :: Middle => acc + item,
831
+ Position :: First => acc - 2 * item,
832
+ Position :: Last => acc + 2 * item,
833
+ Position :: Only => acc + 5 * item,
834
+ } )
835
+ } )
836
+ } ) ;
837
+ }
838
+
822
839
criterion_group ! (
823
840
benches,
824
841
slice_iter,
@@ -866,5 +883,6 @@ criterion_group!(
866
883
permutations_iter,
867
884
permutations_range,
868
885
permutations_slice,
886
+ with_position_fold,
869
887
) ;
870
888
criterion_main ! ( benches) ;
You can’t perform that action at this time.
0 commit comments