1
1
use criterion:: { black_box, criterion_group, criterion_main, Criterion } ;
2
2
use itertools:: free:: cloned;
3
+ use itertools:: iproduct;
3
4
use itertools:: Itertools ;
4
- use itertools:: Position ;
5
- use itertools:: { iproduct, EitherOrBoth } ;
6
5
7
6
use std:: cmp;
8
7
use std:: iter:: repeat;
@@ -391,25 +390,6 @@ fn zip_unchecked_counted_loop3(c: &mut Criterion) {
391
390
} ) ;
392
391
}
393
392
394
- fn ziplongest ( c : & mut Criterion ) {
395
- let v1 = black_box ( ( 0 ..768 ) . collect_vec ( ) ) ;
396
- let v2 = black_box ( ( 0 ..1024 ) . collect_vec ( ) ) ;
397
- c. bench_function ( "ziplongest" , move |b| {
398
- b. iter ( || {
399
- let zip = v1. iter ( ) . zip_longest ( v2. iter ( ) ) ;
400
- let sum = zip. fold ( 0u32 , |mut acc, val| {
401
- match val {
402
- EitherOrBoth :: Both ( x, y) => acc += x * y,
403
- EitherOrBoth :: Left ( x) => acc += x,
404
- EitherOrBoth :: Right ( y) => acc += y,
405
- }
406
- acc
407
- } ) ;
408
- sum
409
- } )
410
- } ) ;
411
- }
412
-
413
393
fn group_by_lazy_1 ( c : & mut Criterion ) {
414
394
let mut data = vec ! [ 0 ; 1024 ] ;
415
395
for ( index, elt) in data. iter_mut ( ) . enumerate ( ) {
@@ -448,25 +428,6 @@ fn group_by_lazy_2(c: &mut Criterion) {
448
428
} ) ;
449
429
}
450
430
451
- fn while_some ( c : & mut Criterion ) {
452
- c. bench_function ( "while_some" , |b| {
453
- b. iter ( || {
454
- let data = black_box (
455
- ( 0 ..)
456
- . fuse ( )
457
- . map ( |i| std:: char:: from_digit ( i, 16 ) )
458
- . while_some ( ) ,
459
- ) ;
460
- // let result: String = data.fold(String::new(), |acc, ch| acc + &ch.to_string());
461
- let result = data. fold ( String :: new ( ) , |mut acc, ch| {
462
- acc. push ( ch) ;
463
- acc
464
- } ) ;
465
- assert_eq ! ( result. as_str( ) , "0123456789abcdef" ) ;
466
- } ) ;
467
- } ) ;
468
- }
469
-
470
431
fn slice_chunks ( c : & mut Criterion ) {
471
432
let data = vec ! [ 0 ; 1024 ] ;
472
433
@@ -703,22 +664,6 @@ fn cartesian_product_iterator(c: &mut Criterion) {
703
664
} ) ;
704
665
}
705
666
706
- fn cartesian_product_fold ( c : & mut Criterion ) {
707
- let xs = vec ! [ 0 ; 16 ] ;
708
-
709
- c. bench_function ( "cartesian product fold" , move |b| {
710
- b. iter ( || {
711
- let mut sum = 0 ;
712
- iproduct ! ( & xs, & xs, & xs) . fold ( ( ) , |( ) , ( & x, & y, & z) | {
713
- sum += x;
714
- sum += y;
715
- sum += z;
716
- } ) ;
717
- sum
718
- } )
719
- } ) ;
720
- }
721
-
722
667
fn multi_cartesian_product_iterator ( c : & mut Criterion ) {
723
668
let xs = [ vec ! [ 0 ; 16 ] , vec ! [ 0 ; 16 ] , vec ! [ 0 ; 16 ] ] ;
724
669
@@ -735,22 +680,6 @@ fn multi_cartesian_product_iterator(c: &mut Criterion) {
735
680
} ) ;
736
681
}
737
682
738
- fn multi_cartesian_product_fold ( c : & mut Criterion ) {
739
- let xs = [ vec ! [ 0 ; 16 ] , vec ! [ 0 ; 16 ] , vec ! [ 0 ; 16 ] ] ;
740
-
741
- c. bench_function ( "multi cartesian product fold" , move |b| {
742
- b. iter ( || {
743
- let mut sum = 0 ;
744
- xs. iter ( ) . multi_cartesian_product ( ) . fold ( ( ) , |( ) , x| {
745
- sum += x[ 0 ] ;
746
- sum += x[ 1 ] ;
747
- sum += x[ 2 ] ;
748
- } ) ;
749
- sum
750
- } )
751
- } ) ;
752
- }
753
-
754
683
fn cartesian_product_nested_for ( c : & mut Criterion ) {
755
684
let xs = vec ! [ 0 ; 16 ] ;
756
685
@@ -839,33 +768,6 @@ fn permutations_slice(c: &mut Criterion) {
839
768
} ) ;
840
769
}
841
770
842
- fn with_position_fold ( c : & mut Criterion ) {
843
- let v = black_box ( ( 0 ..10240 ) . collect_vec ( ) ) ;
844
- c. bench_function ( "with_position fold" , move |b| {
845
- b. iter ( || {
846
- v. iter ( )
847
- . with_position ( )
848
- . fold ( 0 , |acc, ( pos, & item) | match pos {
849
- Position :: Middle => acc + item,
850
- Position :: First => acc - 2 * item,
851
- Position :: Last => acc + 2 * item,
852
- Position :: Only => acc + 5 * item,
853
- } )
854
- } )
855
- } ) ;
856
- }
857
-
858
- fn tuple_combinations_fold ( c : & mut Criterion ) {
859
- let v = black_box ( ( 0 ..64 ) . collect_vec ( ) ) ;
860
- c. bench_function ( "tuple_combinations fold" , move |b| {
861
- b. iter ( || {
862
- v. iter ( )
863
- . tuple_combinations ( )
864
- . fold ( 0 , |acc, ( a, b, c, d) | acc + * a * * c - * b * * d)
865
- } )
866
- } ) ;
867
- }
868
-
869
771
criterion_group ! (
870
772
benches,
871
773
slice_iter,
@@ -887,7 +789,6 @@ criterion_group!(
887
789
zipdot_i32_unchecked_counted_loop,
888
790
zipdot_f32_unchecked_counted_loop,
889
791
zip_unchecked_counted_loop3,
890
- ziplongest,
891
792
group_by_lazy_1,
892
793
group_by_lazy_2,
893
794
slice_chunks,
@@ -903,18 +804,13 @@ criterion_group!(
903
804
step_range_2,
904
805
step_range_10,
905
806
cartesian_product_iterator,
906
- cartesian_product_fold,
907
807
multi_cartesian_product_iterator,
908
- multi_cartesian_product_fold,
909
808
cartesian_product_nested_for,
910
809
all_equal,
911
810
all_equal_for,
912
811
all_equal_default,
913
812
permutations_iter,
914
813
permutations_range,
915
814
permutations_slice,
916
- with_position_fold,
917
- tuple_combinations_fold,
918
- while_some,
919
815
) ;
920
816
criterion_main ! ( benches) ;
0 commit comments