1 个不稳定版本
0.1.1 | 2021 年 6 月 30 日 |
---|
#1241 在 开发工具
20KB
325 行代码(不包括注释)
exec_duration
获取函数或代码块的执行时间
简单易用的 Rust 代码性能分析库。
此模块提供简单的 API 来测量函数或代码块的执行时间。
安装
[dependencies]
exec_duration = "0.1.1"
示例
use exec_duration::ExecProbe;
fn function_1() {
// Create a new execution probe object
// exec duration will be computed from this point
let mut ep = ExecProbe::new("function_1");
// some code
// add a new point
ep.add_point("part 1");
// some code
// add a new point
ep.add_point("part 2");
// some code
// add a new point
ep.add_point("part 3");
}
fn function_2() {
// Create a new execution probe object
// exec duration will be computed from this point
let mut ep = ExecProbe::new("function_2");
// some code
// add a new point
ep.add_point("part 1");
// some code
// add a new point
ep.add_point("part 2");
// some code
// optionally call the stop function
ep.stop();
}
fn main() {
function_1();
function_2();
// fetch results
if let Ok(list) = exec_duration::fetch_results() {
for r in list.iter() {
println!("{}", r);
}
}
}
依赖项
~190KB