Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Profiling and Benchmarking | Rust Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Rust Fundamentals

Lesson 45 of 50

·rust

Profiling and Benchmarking

15 minutes

Course progress90%

Profiling and Benchmarking

Use the criterion crate for micro‑benchmarks.

[dev-dependencies]
criterion = \"0.4\"
use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn fibonacci(n: )   {
     n {
         => ,
         => ,
        _ => (n-) + (n-),
    }
}

 (c: & Criterion) {
    c.(\
u64
->
u64
match
0
0
1
1
fibonacci
1
fibonacci
2
fn
bench_fib
mut
bench_function
"fib 20\", |b| b.iter(|| fibonacci(black_box(20)))); } criterion_group!(benches, bench_fib); criterion_main!(benches);

Run with cargo bench.

Make it stickPractice what you've learned1 quiz · 1 practical test · Optional activities from Rust FundamentalsBrowse activities
Previous lessonPerformance OptimizationContinue to lesson 46Smart Pointers (Box, Rc, Arc)Back to Rust Fundamentals curriculum