Merge pull request 'docs(clawhdf5): document DType variants, fix unresolved doc links' (#17) from sdlc-docs/clawhdf5-types-20260514-165210 into main

This commit is contained in:
redclawsystems
2026-05-14 23:54:48 +00:00
commit 3f222f6956
3030 changed files with 89917 additions and 0 deletions
@@ -0,0 +1,99 @@
//! Benchmark: all compression backends — deflate, LZ4, zstd.
//!
//! Run with specific features:
//! cargo bench -p clawhdf5-filters --features lz4,zstd --bench compression_bench
#![allow(unexpected_cfgs)]
use criterion::{Criterion, black_box, criterion_group, criterion_main};
/// Generate test data simulating 1M f64 values with a sin() pattern.
fn generate_test_data(size: usize) -> Vec<u8> {
(0..size)
.map(|i| ((i as f64 * 0.01).sin() * 127.0 + 128.0) as u8)
.collect()
}
fn bench_deflate(c: &mut Criterion) {
let data = generate_test_data(8_000_000); // 1M f64 = 8MB
c.bench_function("deflate_compress_level6_8MB", |b| {
b.iter(|| clawhdf5_filters::deflate_compress(black_box(&data), 6).unwrap())
});
let compressed = clawhdf5_filters::deflate_compress(&data, 6).unwrap();
c.bench_function("deflate_decompress_8MB", |b| {
b.iter(|| clawhdf5_filters::deflate_decompress(black_box(&compressed), data.len()).unwrap())
});
}
#[cfg(feature = "lz4")]
fn bench_lz4(c: &mut Criterion) {
let data = generate_test_data(8_000_000);
c.bench_function("lz4_compress_8MB", |b| {
b.iter(|| clawhdf5_filters::lz4_compress(black_box(&data)).unwrap())
});
let compressed = clawhdf5_filters::lz4_compress(&data).unwrap();
c.bench_function("lz4_decompress_8MB", |b| {
b.iter(|| clawhdf5_filters::lz4_decompress(black_box(&compressed)).unwrap())
});
}
#[cfg(feature = "zstd")]
fn bench_zstd(c: &mut Criterion) {
let data = generate_test_data(8_000_000);
c.bench_function("zstd_compress_level1_8MB", |b| {
b.iter(|| clawhdf5_filters::zstd_compress(black_box(&data), 1).unwrap())
});
c.bench_function("zstd_compress_level3_8MB", |b| {
b.iter(|| clawhdf5_filters::zstd_compress(black_box(&data), 3).unwrap())
});
let compressed = clawhdf5_filters::zstd_compress(&data, 3).unwrap();
c.bench_function("zstd_decompress_8MB", |b| {
b.iter(|| clawhdf5_filters::zstd_decompress(black_box(&compressed)).unwrap())
});
}
fn bench_parallel_deflate(c: &mut Criterion) {
// 10 chunks of ~800KB each
let chunks: Vec<Vec<u8>> = (0..10)
.map(|i| generate_test_data(800_000 + i * 1000))
.collect();
c.bench_function("deflate_sequential_10chunks", |b| {
b.iter(|| {
let refs: Vec<&[u8]> = chunks.iter().map(|c| c.as_slice()).collect();
black_box(&refs)
.iter()
.map(|data| clawhdf5_filters::deflate_compress(data, 6))
.collect::<Result<Vec<_>, _>>()
.unwrap()
})
});
}
criterion_group!(benches, bench_deflate, bench_parallel_deflate,);
#[cfg(feature = "lz4")]
criterion_group!(lz4_benches, bench_lz4);
#[cfg(feature = "zstd")]
criterion_group!(zstd_benches, bench_zstd);
// Combine all benchmark groups
#[cfg(all(feature = "lz4", feature = "zstd"))]
criterion_main!(benches, lz4_benches, zstd_benches);
#[cfg(all(feature = "lz4", not(feature = "zstd")))]
criterion_main!(benches, lz4_benches);
#[cfg(all(not(feature = "lz4"), feature = "zstd"))]
criterion_main!(benches, zstd_benches);
#[cfg(not(any(feature = "lz4", feature = "zstd")))]
criterion_main!(benches);
@@ -0,0 +1,83 @@
//! Benchmark: deflate compression/decompression across backends.
//!
//! Both the active backend (zlib-ng or apple-compression) and the pure-Rust
//! miniz_oxide baseline are tested in each run for direct comparison.
//!
//! Run:
//! cargo bench -p clawhdf5-filters -- deflate
use criterion::{Criterion, black_box, criterion_group, criterion_main};
fn generate_sine_data(size: usize) -> Vec<u8> {
(0..size)
.map(|i| ((i as f64 * 0.01).sin() * 127.0 + 128.0) as u8)
.collect()
}
/// Generate 1M f64 values as raw bytes — matches the purehdf5-format bench pattern.
fn generate_f64_data(n: usize) -> Vec<u8> {
(0..n).flat_map(|i| (i as f64).to_le_bytes()).collect()
}
fn bench_compress_1mb(c: &mut Criterion) {
let data = generate_sine_data(1_000_000);
let backend = clawhdf5_filters::deflate_backend();
c.bench_function(&format!("deflate_compress_1MB ({backend})"), |b| {
b.iter(|| clawhdf5_filters::deflate_compress(black_box(&data), 6).unwrap())
});
c.bench_function("deflate_compress_1MB (miniz_oxide)", |b| {
b.iter(|| clawhdf5_filters::deflate_compress_miniz(black_box(&data), 6).unwrap())
});
}
fn bench_decompress_1mb(c: &mut Criterion) {
let data = generate_sine_data(1_000_000);
let compressed = clawhdf5_filters::deflate_compress_miniz(&data, 6).unwrap();
let backend = clawhdf5_filters::deflate_backend();
c.bench_function(&format!("deflate_decompress_1MB ({backend})"), |b| {
b.iter(|| clawhdf5_filters::deflate_decompress(black_box(&compressed), data.len()).unwrap())
});
c.bench_function("deflate_decompress_1MB (miniz_oxide)", |b| {
b.iter(|| clawhdf5_filters::deflate_decompress_miniz(black_box(&compressed)).unwrap())
});
}
fn bench_compress_f64(c: &mut Criterion) {
let data = generate_f64_data(1_000_000);
let backend = clawhdf5_filters::deflate_backend();
c.bench_function(&format!("deflate_compress_8MB_f64 ({backend})"), |b| {
b.iter(|| clawhdf5_filters::deflate_compress(black_box(&data), 6).unwrap())
});
c.bench_function("deflate_compress_8MB_f64 (miniz_oxide)", |b| {
b.iter(|| clawhdf5_filters::deflate_compress_miniz(black_box(&data), 6).unwrap())
});
}
fn bench_decompress_f64(c: &mut Criterion) {
let data = generate_f64_data(1_000_000);
let compressed = clawhdf5_filters::deflate_compress_miniz(&data, 6).unwrap();
let backend = clawhdf5_filters::deflate_backend();
c.bench_function(&format!("deflate_decompress_8MB_f64 ({backend})"), |b| {
b.iter(|| clawhdf5_filters::deflate_decompress(black_box(&compressed), data.len()).unwrap())
});
c.bench_function("deflate_decompress_8MB_f64 (miniz_oxide)", |b| {
b.iter(|| clawhdf5_filters::deflate_decompress_miniz(black_box(&compressed)).unwrap())
});
}
criterion_group!(
benches,
bench_compress_1mb,
bench_decompress_1mb,
bench_compress_f64,
bench_decompress_f64,
);
criterion_main!(benches);