weirflow 0.1.0

GPU-first dataflow analysis primitives for Vyre and Santh compiler pipelines.
Documentation
//! Benchmark `CsrGraph::normalize` at four scale points.

use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use weir::graph_layout::CsrGraph;

/// Build a CSR where every node has 2 outgoing edges (cyclic).
fn build_csr(node_count: u32, edge_count: u32) -> (Vec<u32>, Vec<u32>, Vec<u32>) {
    let mut offsets = Vec::with_capacity(node_count as usize + 1);
    let mut targets = Vec::with_capacity(edge_count as usize);
    let mut masks = Vec::with_capacity(edge_count as usize);
    offsets.push(0);
    let mut running = 0u32;
    for node in 0..node_count {
        for delta in 1..=2 {
            if running >= edge_count {
                break;
            }
            let dst = (node + delta) % node_count.max(1);
            targets.push(dst);
            masks.push(1);
            running += 1;
        }
        offsets.push(running);
    }
    (offsets, targets, masks)
}

fn bench_csr_normalize(c: &mut Criterion) {
    let mut group = c.benchmark_group("csr_normalize");
    for &(name, nodes, edges) in &[
        ("tiny", 10u32, 20u32),
        ("small", 1_000, 2_000),
        ("medium", 100_000, 200_000),
        ("large", 1_000_000, 2_000_000),
    ] {
        let (offsets, targets, masks) = build_csr(nodes, edges);
        group.throughput(Throughput::Elements(nodes as u64));
        group.bench_with_input(
            BenchmarkId::new(name, nodes),
            &(nodes, offsets, targets, masks),
            |b, (n, offsets, targets, masks)| {
                b.iter(|| {
                    let graph = CsrGraph::new(*n, offsets, targets, masks);
                    let _ = black_box(graph.normalize("benchmark"));
                });
            },
        );
    }
    group.finish();
}

criterion_group!(benches, bench_csr_normalize);
criterion_main!(benches);