pdfrum-edit 0.1.1

PDF serializer: full/incremental save, page import, subsetting
Documentation
//! Full rewrite to memory. Ids `<class>/<stem>`.
//!
//! Disk would measure the page cache. No oracle column: `pdfium_test` has
//! no full-rewrite mode.

use std::hint::black_box;
use std::time::Duration;

use criterion::{Criterion, criterion_main};
use pdfrum::{Document, SaveOptions};
use pdfrum_corpus::{CORPUS, bytes};

/// A full rewrite, to memory.
fn save(c: &mut Criterion) {
    let mut group = c.benchmark_group("save");
    let options = SaveOptions::default();
    for doc in CORPUS {
        let Ok(opened) = Document::from_bytes(bytes(doc.stem)) else {
            continue;
        };
        group.bench_function(format!("{}/{}", doc.class.name(), doc.stem), |b| {
            b.iter(|| {
                let mut out = Vec::new();
                black_box(opened.write_to(&mut out, &options).ok());
                black_box(out.len())
            });
        });
    }
    group.finish();
}

// `criterion_group!` generates a `pub fn` the `missing_docs` lint cannot see a
// doc comment for — the attribute would land inside the macro's expansion.
#[allow(missing_docs, reason = "the item is generated by criterion_group!")]
mod group {
    use super::{Criterion, Duration, save};
    use criterion::criterion_group;

    criterion_group! {
        name = benches;
        // measurement behind them.
        config = Criterion::default()
            .measurement_time(Duration::from_secs(5))
            .warm_up_time(Duration::from_secs(2))
            .sample_size(50);
        targets = save
    }
}

criterion_main!(group::benches);