You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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

正确的写法有两种:

  1. 将完整的被测命令(含参数)用引号括起来
    这种方式让hyperfine把整个字符串当作单个命令执行,适合Windows环境:
hyperfine --runs 3 ".\target\release\examples\cover_types 1 0.1 0.1"
  1. 使用--分隔hyperfine选项与被测命令参数
    --需要放在hyperfine的所有选项之后,之后的内容都会被当作被测程序的路径和参数:
hyperfine --runs 3 -- .\target\release\examples\cover_types 1 0.1 0.1

错误写法的原因:

  • 第一种错误写法把--放在了程序路径之后,hyperfine会将--识别为被测程序的参数,而非分隔符;
  • -L是hyperfine的参数化测试选项(用于循环遍历不同参数值),不是用来传递固定参数的,因此不适用当前场景。

内容的提问来源于stack exchange,提问作者Mutlu Simsek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 04:33:22