rust计算程序运行时间

main.rs

use std::thread::sleep;
use std::time::{Duration,Instant};
fn main() {

    let now = Instant::now();  // 程序起始时间
    println!("{:?}",now);  

    let three_seconds = Duration::from_secs(3);
    sleep(three_seconds);  // 延迟3秒

    let end = now.elapsed().as_secs();
    println!("程序运行了 {:?} 秒",end);     // 程序终止时间


}


posted @ 2022-09-19 13:59  Nazorine  阅读(1445)  评论(0)    收藏  举报