« Back to Index

Rust: Measure the elapsed time between two code sections in Rust

View original Gist on GitHub

Tags: #rust #debug

main.rs

use std::time::{Duration, Instant};

fn main() {
    let start = Instant::now();
    expensive_function();
    let duration = start.elapsed();

    println!("Time elapsed in expensive_function() is: {:?}", duration);
}