Files
Andy Dixon 9179281a94 Describe behaviour directly instead of by reference to the Go version
- platform::mode documents the on-disk mode-bit layout (bits 31..19 =
  d a l T L D p S u g c t ?, low 9 bits = permissions).
- The snapshot module documents the LEB128 / zig-zag varints and the RFC
  3339 JSON timestamps, and states that snapshots written by mapsize 1.x
  load unchanged.
- Renames: GoTime -> JsonTime, go_duration -> fmt_duration, fixture
  testdata/go.msz -> testdata/v1.2.0.msz (a snapshot written by mapsize
  1.2.0), loads_go_snapshot -> loads_1_2_snapshot.
- --log / --log-level help says they are accepted and ignored.
2026-10-08 20:08:34 +01:00

79 lines
2.4 KiB
Rust

//! In-process benchmarks of the TUI model (render, navigation, filtering)
//! and the treemap layout:
//!
//! cargo run --release --example bench
//!
//! Each case runs for ~2 s after a warm-up and reports the mean time per op.
use mapsize::treemap::{self, Direction, Item, Rect};
use mapsize::tui::bench::{big_tree, BenchModel};
use std::hint::black_box;
use std::sync::{Arc, RwLock};
use std::time::{Duration, Instant};
fn bench<R>(name: &str, mut f: impl FnMut(u64) -> R) {
black_box(f(0));
let budget = Duration::from_secs(2);
let start = Instant::now();
let mut n = 0u64;
while start.elapsed() < budget {
black_box(f(n));
n += 1;
}
let per = start.elapsed() / n as u32;
println!("{name:<40} {n:>8} ops {per:>12.2?}/op");
}
fn main() {
let items: Vec<Item> = (0..300)
.map(|i| Item {
id: i,
size: (1 + i * i) as f64,
})
.collect();
let bounds = Rect {
x: 0,
y: 0,
w: 200,
h: 60,
};
bench("treemap/Squarify(300)", |_| {
black_box(treemap::squarify(black_box(&items), bounds));
});
let blocks = treemap::squarify(&items, bounds);
bench("treemap/Neighbour(300)", |_| {
black_box(treemap::neighbour(
black_box(&blocks),
150,
Direction::Right,
));
});
let t0 = Instant::now();
let tree = Arc::new(RwLock::new(big_tree()));
println!(
"big tree: {} nodes built in {:.2?}",
tree.read().unwrap().len(),
t0.elapsed()
);
let mut m = BenchModel::new(tree.clone(), 200, 60);
bench("tui/BigColdFrame", |_| m.cold_frame());
let mut m = BenchModel::new(tree.clone(), 200, 60);
m.cold_frame();
bench("tui/BigResize", |i| {
m.resize(150 + (i % 100) as u16, 40 + (i % 30) as u16)
});
let mut m = BenchModel::new(tree.clone(), 200, 60);
m.zoom_to_child_named(b"flat");
bench("tui/BigFlatDirCold", |_| m.cold_frame());
let mut m = BenchModel::new(tree.clone(), 200, 60);
m.cold_frame();
let keys = ["right", "down", "left", "up"];
bench("tui/BigNavigate", |i| m.key(keys[i as usize % 4]));
for q in ["size > 1MB", "*.dat AND size > 500k", "path contains sub3"] {
let mut m = BenchModel::new(tree.clone(), 200, 60);
bench(&format!("tui/BigFilter/{q}"), |_| m.apply_filter(q));
}
}