gil 0.9.0

A collection of high-performance, lock-free concurrent queues (SPSC, MPSC, MPMC, SPMC) with sync and async support
Documentation
use gil::mpmc::channel;
use std::{hint::black_box, num::NonZeroUsize, thread::spawn, time::Instant};

fn main() {
    let (tx, rx) = channel(NonZeroUsize::new(4096).unwrap());

    const SENDERS: usize = 4;
    const MESSAGES: usize = 50_000_000;

    let start = Instant::now();

    for _ in 0..SENDERS {
        let mut tx = tx.clone();
        spawn(move || {
            for i in 0..MESSAGES {
                tx.send(black_box(i));
            }
        });
    }

    // Drop the original sender since we've cloned it for all threads
    drop(tx);

    let mut handles = Vec::with_capacity(SENDERS);
    for _ in 0..SENDERS {
        let mut rx = rx.clone();
        handles.push(spawn(move || {
            for _ in 0..MESSAGES {
                let x = rx.recv();
                black_box(x);
            }
        }));
    }

    // Drop the original receiver since we've cloned it for all threads
    drop(rx);

    for handle in handles {
        handle.join().unwrap();
    }

    let time = start.elapsed();
    println!(
        "time={time:?}\nmil/s={throughput:.2}",
        throughput = MESSAGES as f64 / 1_000_000.0 / time.as_secs_f64()
    );
}