quickring 0.1.0

A very fast, lock-free SPSC ring buffer.
Documentation
  • Coverage
  • 70%
    7 out of 10 items documented0 out of 9 items with examples
  • Size
  • Source code size: 377.49 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.56 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • avhz/quickring
    5 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • avhz

quickring

This library provides a very fast, lock-free SPSC ring buffer implementation in Rust.

It can perform 1 billion writes and reads in ~1.76s on my MacBook Air M2, on usize data with a capacity of 8192.

Features

  • Very high performance.
  • Generic over any data type.
  • Compile-time static capacity.
  • Split into producer and consumer (SPSC) for concurrent use.

Usage

Run cargo add quickring to add it to your project, or add the following to your Cargo.toml:

[dependencies]
quickring = "*"

Then, you can use it as follows:

use quickring::RingBuffer;

const OPERATIONS: usize = 1_000_000;
const CAPACITY: usize = 1 << 13; // 8192


let rb: RingBuffer<usize, CAPACITY> = RingBuffer::new();
let (mut tx, mut rx) = rb.split();

// Create a producer thread
let producer = std::thread::spawn(move || {
    for i in 0..OPERATIONS {
        while !tx.push(i) {}
    }
});

// Create a consumer thread
let consumer = std::thread::spawn(move || {
    for _ in 0..OPERATIONS {
        loop {
            if let Some(_) = rx.pop() {
                break;
            }
        }
    }
});

producer.join().unwrap();
consumer.join().unwrap();