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 ;
1
2
use core:: iter:: * ;
2
3
use core:: mem;
3
4
use core:: num:: Wrapping ;
@@ -403,13 +404,31 @@ fn bench_trusted_random_access_adapters(b: &mut Bencher) {
403
404
404
405
/// Exercises the iter::Copied specialization for slice::Iter
405
406
#[ 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 ) {
407
425
let v = vec ! [ 1u8 ; 1024 ] ;
408
426
409
427
b. iter ( || {
410
428
black_box ( & v)
411
429
. iter ( )
412
- . copied ( )
430
+ // this shows that we're not relying on the slice::Iter specialization in Copied
431
+ . map ( |b| * b. borrow ( ) )
413
432
. array_chunks :: < { mem:: size_of :: < u64 > ( ) } > ( )
414
433
. map ( |ary| {
415
434
let d = u64:: from_ne_bytes ( ary) ;
Original file line number Diff line number Diff line change 5
5
#![ feature( test) ]
6
6
#![ feature( trusted_random_access) ]
7
7
#![ feature( iter_array_chunks) ]
8
+ #![ feature( iter_next_chunk) ]
8
9
9
10
extern crate test;
10
11
You can’t perform that action at this time.
0 commit comments