gpt4 book ai didi

time - 使用 Cargo 获取执行时间

转载 作者:行者123 更新时间:2023-11-29 08:22:10 25 4
gpt4 key购买 nike

我是 Rust 的新手,我想为我的程序的执行计时。我在网上搜索,但到目前为止一无所获。运行 cargo build 后,我的代码是这样执行的:

bling@bling ~/github/rust/hello_world [master *]
± % ./target/debug/hello_world

Cargo 是否有内置的方式来计时执行,或者我是否需要使用命令行?

最佳答案

我认为您不能将标志直接传递给 cargo 来为编译步骤计时。最简单的方法是使用 time 命令行实用程序:

$ time ./target/debug/hello_world
./target/debug/hello_world 3.02s user 0.18s system 34% cpu 9.177 total

Cargo 确实有类似的东西:cargo bench 允许你为你的程序编写基准测试,尽管它只在夜间 Rust 上可用。这会为您提供有关程序某些部分速度的非常具体的报告。 The docs have more reading .

$ cargo bench
running 1 test
test bench_xor_1000_ints ... bench: 131 ns/iter (+/- 3)

关于time - 使用 Cargo 获取执行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33554670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com