如何在Rust中为hyperfine传递命令行参数?
如何给hyperfine命令传递程序参数?
我可以通过以下cargo命令带参数运行程序:
cargo run --release --example cover_types 1 0.1 0.1
但直接用hyperfine运行编译后的二进制文件时,带参数的写法无法生效:
hyperfine --runs 3 .\target\release\examples\cover_types 1 0.1 0.1
尝试了以下写法也没用:
hyperfine --runs 3 .\target\release\examples\cover_types -- 1 0.1 0.1 hyperfine --runs 3 .\target\release\examples\cover_types -L 1 0.1 0.1
正确的写法有两种:
- 将完整的被测命令(含参数)用引号括起来
这种方式让hyperfine把整个字符串当作单个命令执行,适合Windows环境:
hyperfine --runs 3 ".\target\release\examples\cover_types 1 0.1 0.1"
- 使用
--分隔hyperfine选项与被测命令参数--需要放在hyperfine的所有选项之后,之后的内容都会被当作被测程序的路径和参数:
hyperfine --runs 3 -- .\target\release\examples\cover_types 1 0.1 0.1
错误写法的原因:
- 第一种错误写法把
--放在了程序路径之后,hyperfine会将--识别为被测程序的参数,而非分隔符; -L是hyperfine的参数化测试选项(用于循环遍历不同参数值),不是用来传递固定参数的,因此不适用当前场景。
内容的提问来源于stack exchange,提问作者Mutlu Simsek
相关产品推荐
相关产品推荐

