//! Times SAM 3 on this machine (a synthetic gradient image; the first run includes compiling //! the GPU kernels): `cargo run -p lightcraft-segment --release --example sam3_bench -- `. fn main() -> Result<(), Box> { let mut args = std::env::args().skip(1); let dir = std::path::PathBuf::from(args.next().ok_or("usage: sam3_bench ")?); let t = std::time::Instant::now(); let mut model = lightcraft_segment::Sam3::load(&dir)?; eprintln!("load: {:?} on {:?}", t.elapsed(), model.device()); let (w, h) = (1200, 800); let rgb: Vec = (0..w * h * 3).map(|i| ((i / 3 % w) * 255 / w) as u8).collect(); for run in 0..3 { let t = std::time::Instant::now(); let mut enc = model.encode(&rgb, w, h)?; lightcraft_segment::sync(&model)?; let e = t.elapsed(); let t = std::time::Instant::now(); let p = model.segment_clicks(&mut enc, &[lightcraft_segment::Click { x: 0.5, y: 0.5, positive: true }])?; let c = t.elapsed(); let t = std::time::Instant::now(); let d = model.segment_text(&mut enc, "sky", 0.5)?; eprintln!("run {run}: encode {e:?}, click {c:?} (score {:.2}), text {:?} ({})", p.score, t.elapsed(), d.is_some()); } Ok(()) }