| 80 | tags = "core" |
| 81 | )] |
| 82 | fn spsc_cross_thread(b: &mut Bencher) { |
| 83 | const COUNT: usize = 100_000; |
| 84 | |
| 85 | b.iter(|| { |
| 86 | let (mut prod, mut cons) = RingBuffer::channel::<Vec<u8>>(8192); |
| 87 | let payload = vec![0xABu8; MSG_SIZE]; |
| 88 | |
| 89 | let consumer = std::thread::spawn(move || { |
| 90 | let mut received = 0usize; |
| 91 | while received < COUNT { |
| 92 | if cons.try_pop().is_ok() { |
| 93 | received += 1; |
| 94 | } else { |
| 95 | std::hint::spin_loop(); |
| 96 | } |
| 97 | } |
| 98 | received |
| 99 | }); |
| 100 | |
| 101 | let mut sent = 0usize; |
| 102 | while sent < COUNT { |
| 103 | if prod.try_push(payload.clone()).is_ok() { |
| 104 | sent += 1; |
| 105 | } else { |
| 106 | std::hint::spin_loop(); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | let received = consumer.join().unwrap(); |
| 111 | black_box(received) |
| 112 | }); |
| 113 | } |
| 114 | |
| 115 | // 100K messages * 256 bytes = 25.6 MB per iteration. |
| 116 | #[synthetic( |