|
| 1 | +// SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 3 | +// |
| 4 | +// benches/git_reticulator_bench.rs |
| 5 | +// Criterion benchmarks for git-reticulator. |
| 6 | +// |
| 7 | +// Baselines measured: |
| 8 | +// B1 - build_lattice with a short repo path and db URI |
| 9 | +// B2 - query_lattice with a short zoom node and db URI |
| 10 | +// B3 - build_lattice with a long (4 KiB) repo path |
| 11 | +// B4 - query_lattice with a long (4 KiB) zoom node |
| 12 | +// B5 - Sequential build-then-query pipeline |
| 13 | + |
| 14 | +use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; |
| 15 | +use git_reticulator::lattice::affine; |
| 16 | + |
| 17 | +// --------------------------------------------------------------------------- |
| 18 | +// B1: build_lattice — short inputs |
| 19 | +// --------------------------------------------------------------------------- |
| 20 | +fn bench_build_lattice_short(c: &mut Criterion) { |
| 21 | + c.bench_function("build_lattice/short", |b| { |
| 22 | + b.iter(|| { |
| 23 | + affine::build_lattice( |
| 24 | + black_box("github.com/hyperpolymath/git-reticulator"), |
| 25 | + black_box("postgres://localhost:5432/reticulator"), |
| 26 | + ) |
| 27 | + }) |
| 28 | + }); |
| 29 | +} |
| 30 | + |
| 31 | +// --------------------------------------------------------------------------- |
| 32 | +// B2: query_lattice — short inputs |
| 33 | +// --------------------------------------------------------------------------- |
| 34 | +fn bench_query_lattice_short(c: &mut Criterion) { |
| 35 | + c.bench_function("query_lattice/short", |b| { |
| 36 | + b.iter(|| { |
| 37 | + affine::query_lattice( |
| 38 | + black_box("module::lattice::affine"), |
| 39 | + black_box("postgres://localhost:5432/reticulator"), |
| 40 | + ) |
| 41 | + }) |
| 42 | + }); |
| 43 | +} |
| 44 | + |
| 45 | +// --------------------------------------------------------------------------- |
| 46 | +// B3: build_lattice — long inputs (4 KiB) |
| 47 | +// --------------------------------------------------------------------------- |
| 48 | +fn bench_build_lattice_long(c: &mut Criterion) { |
| 49 | + let long_repo: String = "repo/".repeat(819); // ~4 KiB |
| 50 | + let long_db: String = "db://".repeat(819); |
| 51 | + |
| 52 | + c.bench_function("build_lattice/long_4kib", |b| { |
| 53 | + b.iter(|| affine::build_lattice(black_box(&long_repo), black_box(&long_db))) |
| 54 | + }); |
| 55 | +} |
| 56 | + |
| 57 | +// --------------------------------------------------------------------------- |
| 58 | +// B4: query_lattice — long inputs (4 KiB) |
| 59 | +// --------------------------------------------------------------------------- |
| 60 | +fn bench_query_lattice_long(c: &mut Criterion) { |
| 61 | + let long_node: String = "node::".repeat(682); // ~4 KiB |
| 62 | + let long_db: String = "db://".repeat(819); |
| 63 | + |
| 64 | + c.bench_function("query_lattice/long_4kib", |b| { |
| 65 | + b.iter(|| affine::query_lattice(black_box(&long_node), black_box(&long_db))) |
| 66 | + }); |
| 67 | +} |
| 68 | + |
| 69 | +// --------------------------------------------------------------------------- |
| 70 | +// B5: Pipeline — build followed immediately by query |
| 71 | +// --------------------------------------------------------------------------- |
| 72 | +fn bench_pipeline(c: &mut Criterion) { |
| 73 | + c.bench_function("pipeline/build_then_query", |b| { |
| 74 | + b.iter(|| { |
| 75 | + affine::build_lattice( |
| 76 | + black_box("pipeline-repo"), |
| 77 | + black_box("pipeline://db"), |
| 78 | + ); |
| 79 | + affine::query_lattice( |
| 80 | + black_box("pipeline-node"), |
| 81 | + black_box("pipeline://db"), |
| 82 | + ); |
| 83 | + }) |
| 84 | + }); |
| 85 | +} |
| 86 | + |
| 87 | +// --------------------------------------------------------------------------- |
| 88 | +// B6: Parametric — varying input lengths |
| 89 | +// --------------------------------------------------------------------------- |
| 90 | +fn bench_build_lattice_parametric(c: &mut Criterion) { |
| 91 | + let mut group = c.benchmark_group("build_lattice/by_input_length"); |
| 92 | + |
| 93 | + for size in [8usize, 64, 256, 1024, 4096] { |
| 94 | + let repo = "x".repeat(size); |
| 95 | + let db = "d".repeat(size); |
| 96 | + group.bench_with_input( |
| 97 | + BenchmarkId::from_parameter(size), |
| 98 | + &(repo, db), |
| 99 | + |b, (r, d)| b.iter(|| affine::build_lattice(black_box(r), black_box(d))), |
| 100 | + ); |
| 101 | + } |
| 102 | + |
| 103 | + group.finish(); |
| 104 | +} |
| 105 | + |
| 106 | +// --------------------------------------------------------------------------- |
| 107 | +// Criterion entry points |
| 108 | +// --------------------------------------------------------------------------- |
| 109 | +criterion_group!( |
| 110 | + benches, |
| 111 | + bench_build_lattice_short, |
| 112 | + bench_query_lattice_short, |
| 113 | + bench_build_lattice_long, |
| 114 | + bench_query_lattice_long, |
| 115 | + bench_pipeline, |
| 116 | + bench_build_lattice_parametric, |
| 117 | +); |
| 118 | +criterion_main!(benches); |
0 commit comments