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); // 程序终止时间
}

浙公网安备 33010602011771号