ticklog 0.1.0

A fast, minimal logging library for Rust, designed for performance-critical applications, e.g. high-frequency trading.
Documentation
//! Producer hot-path latency of a single `info!` call, isolated from
//! the drain by a null sink.

#[path = "common/affinity.rs"]
mod affinity;

use std::io;

use criterion::{criterion_group, criterion_main, Criterion};
use ticklog::{info, Level, LogSink};

/// Discards every record with no work, so the measured time is the producer's.
struct NullSink;

impl LogSink for NullSink {
    fn accept(&mut self, _line: &[u8], _level: Level) -> io::Result<()> {
        Ok(())
    }
}

fn bench_single_record(c: &mut Criterion) {
    affinity::pin_producer_from_env();

    let mut builder = ticklog::builder().sink(NullSink).max_level(Level::Trace);
    if let Some(core) = affinity::drain_core_from_env() {
        builder = builder.drain_affinity(&[core]);
    }
    let guard = builder.build().expect("ticklog build");
    std::mem::forget(guard);

    c.bench_function("info_one_u64", |b| {
        b.iter(|| info!("x={}", criterion::black_box(1u64)));
    });
}

criterion_group! {
    name = benches;
    config = Criterion::default()
        .significance_level(0.01)
        .noise_threshold(0.02)
        .sample_size(200);
    targets = bench_single_record
}
criterion_main!(benches);