File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 1+ use core:: borrow:: Borrow ;
12use core:: iter:: * ;
23use core:: mem;
34use core:: num:: Wrapping ;
@@ -403,13 +404,31 @@ fn bench_trusted_random_access_adapters(b: &mut Bencher) {
403404
404405/// Exercises the iter::Copied specialization for slice::Iter
405406#[ bench]
406- fn bench_copied_array_chunks ( b : & mut Bencher ) {
407+ fn bench_copied_chunks ( b : & mut Bencher ) {
408+ let v = vec ! [ 1u8 ; 1024 ] ;
409+
410+ b. iter ( || {
411+ let mut iter = black_box ( & v) . iter ( ) . copied ( ) ;
412+ let mut acc = Wrapping ( 0 ) ;
413+ // This uses a while-let loop to side-step the TRA specialization in ArrayChunks
414+ while let Ok ( chunk) = iter. next_chunk :: < { mem:: size_of :: < u64 > ( ) } > ( ) {
415+ let d = u64:: from_ne_bytes ( chunk) ;
416+ acc += Wrapping ( d. rotate_left ( 7 ) . wrapping_add ( 1 ) ) ;
417+ }
418+ acc
419+ } )
420+ }
421+
422+ /// Exercises the TrustedRandomAccess specialization in ArrayChunks
423+ #[ bench]
424+ fn bench_trusted_random_access_chunks ( b : & mut Bencher ) {
407425 let v = vec ! [ 1u8 ; 1024 ] ;
408426
409427 b. iter ( || {
410428 black_box ( & v)
411429 . iter ( )
412- . copied ( )
430+ // this shows that we're not relying on the slice::Iter specialization in Copied
431+ . map ( |b| * b. borrow ( ) )
413432 . array_chunks :: < { mem:: size_of :: < u64 > ( ) } > ( )
414433 . map ( |ary| {
415434 let d = u64:: from_ne_bytes ( ary) ;
Original file line number Diff line number Diff line change 55#![ feature( test) ]
66#![ feature( trusted_random_access) ]
77#![ feature( iter_array_chunks) ]
8+ #![ feature( iter_next_chunk) ]
89
910extern crate test;
1011
You can’t perform that action at this time.
0 commit comments