Lesson 44 of 50 · rust
Performance Optimization
Duration: 15 minutes
Lesson 44 of 50 · rust
Duration: 15 minutes
cargo bench for benchmarks.\n- Profile with perf or valgrind.\n- Inline critical sections with #[inline(always)].\n- Prefer stack allocation over heap when possible.\n- Avoid unnecessary clones; use references.\n\nrust\n#[inline(always)]\nfn fast_sum(v: &[i32]) -> i32 {\n v.iter().sum()\n}\n\n