| 1 | use crate::SharedRb; |
| 2 | |
| 3 | use test::{black_box, Bencher}; |
| 4 | |
| 5 | const RB_SIZE: usize = 256; |
| 6 | |
| 7 | #[bench] |
| 8 | fn make_postponed(b: &mut Bencher) { |
| 9 | let buf = SharedRb::<u64, [_; RB_SIZE]>::default(); |
| 10 | let (mut prod, mut cons) = buf.split(); |
| 11 | prod.push_slice(&[1; RB_SIZE / 2]); |
| 12 | b.iter(|| { |
| 13 | black_box(prod.postponed()); |
| 14 | black_box(cons.postponed()); |
| 15 | }); |
| 16 | } |
| 17 | |
| 18 | #[bench] |
| 19 | fn advance(b: &mut Bencher) { |
| 20 | let buf = SharedRb::<u64, [_; RB_SIZE]>::default(); |
| 21 | let (mut prod, mut cons) = buf.split(); |
| 22 | prod.push_slice(&[1; RB_SIZE / 2]); |
| 23 | b.iter(|| { |
| 24 | unsafe { prod.advance(1) }; |
| 25 | unsafe { cons.advance(1) }; |
| 26 | }); |
| 27 | } |
| 28 | |
| 29 | #[bench] |
| 30 | fn advance_postponed(b: &mut Bencher) { |
| 31 | let buf = SharedRb::<u64, [_; RB_SIZE]>::default(); |
| 32 | let (mut prod, mut cons) = buf.split(); |
| 33 | prod.push_slice(&[1; RB_SIZE / 2]); |
| 34 | b.iter(|| { |
| 35 | unsafe { prod.postponed().advance(1) }; |
| 36 | unsafe { cons.postponed().advance(1) }; |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | #[bench] |
| 41 | fn get_occupied_slices(b: &mut Bencher) { |
| 42 | let buf = SharedRb::<u64, [_; RB_SIZE]>::default(); |
| 43 | let (mut prod, mut cons) = buf.split(); |
| 44 | prod.push_slice(&[0; 3 * RB_SIZE / 4]); |
| 45 | cons.skip(RB_SIZE); |
| 46 | prod.push_slice(&[1; RB_SIZE / 2]); |
| 47 | b.iter(|| { |
| 48 | black_box(unsafe { cons.as_mut_uninit_slices() }); |
| 49 | black_box(&mut cons); |
| 50 | }); |
| 51 | } |
| 52 | |
| 53 | #[bench] |
| 54 | fn get_vacant_slices(b: &mut Bencher) { |
| 55 | let buf = SharedRb::<u64, [_; RB_SIZE]>::default(); |
| 56 | let (mut prod, mut cons) = buf.split(); |
| 57 | prod.push_slice(&[0; 1 * RB_SIZE / 4]); |
| 58 | cons.skip(RB_SIZE); |
| 59 | prod.push_slice(&[1; RB_SIZE / 2]); |
| 60 | b.iter(|| { |
| 61 | black_box(unsafe { prod.free_space_as_slices() }); |
| 62 | black_box(&mut prod); |
| 63 | }); |
| 64 | } |