Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit a65c881

Browse files
committed
Introduce hyperfine_command helper
1 parent be305c2 commit a65c881

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

build_system/tests.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::build_sysroot;
22
use super::config;
33
use super::rustc_info::get_wrapper_file_name;
4-
use super::utils::{cargo_command, spawn_and_wait, spawn_and_wait_with_input};
4+
use super::utils::{cargo_command, hyperfine_command, spawn_and_wait, spawn_and_wait_with_input};
55
use build_system::SysrootKind;
66
use std::env;
77
use std::ffi::OsStr;
@@ -231,40 +231,37 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
231231
}),
232232
TestCase::new("bench.simple-raytracer", &|runner| {
233233
runner.in_dir(["simple-raytracer"], |runner| {
234-
let run_runs = env::var("RUN_RUNS").unwrap_or("10".to_string());
234+
let run_runs = env::var("RUN_RUNS").unwrap_or("10".to_string()).parse().unwrap();
235235

236236
if runner.host_triple == runner.target_triple {
237237
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
238-
let mut bench_compile = Command::new("hyperfine");
239-
bench_compile.arg("--runs");
240-
bench_compile.arg(&run_runs);
241-
bench_compile.arg("--warmup");
242-
bench_compile.arg("1");
243-
bench_compile.arg("--prepare");
244-
bench_compile.arg(format!("{:?}", runner.cargo_command("clean", [])));
238+
let prepare = runner.cargo_command("clean", []);
245239

246-
bench_compile.arg("cargo build");
240+
let llvm_build_cmd = cargo_command("cargo", "build", None, Path::new("."));
247241

248242
let cargo_clif = runner
249243
.root_dir
250244
.clone()
251245
.join("build")
252246
.join(get_wrapper_file_name("cargo-clif", "bin"));
253-
let mut clif_build_cmd = cargo_command(cargo_clif, "build", None, Path::new("."));
254-
clif_build_cmd.env("RUSTFLAGS", &runner.rust_flags);
255-
bench_compile.arg(format!("{:?}", clif_build_cmd));
247+
let clif_build_cmd = cargo_command(cargo_clif, "build", None, Path::new("."));
248+
249+
let bench_compile =
250+
hyperfine_command(1, run_runs, Some(prepare), llvm_build_cmd, clif_build_cmd);
256251

257252
spawn_and_wait(bench_compile);
258253

259254
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
260255
fs::copy(PathBuf::from("./target/debug/main"), PathBuf::from("raytracer_cg_clif"))
261256
.unwrap();
262257

263-
let mut bench_run = Command::new("hyperfine");
264-
bench_run.arg("--runs");
265-
bench_run.arg(&run_runs);
266-
bench_run.arg(PathBuf::from("./raytracer_cg_llvm"));
267-
bench_run.arg(PathBuf::from("./raytracer_cg_clif"));
258+
let bench_run = hyperfine_command(
259+
0,
260+
run_runs,
261+
None,
262+
Command::new("./raytracer_cg_llvm"),
263+
Command::new("./raytracer_cg_clif"),
264+
);
268265
spawn_and_wait(bench_run);
269266
} else {
270267
runner.run_cargo("clean", []);

build_system/utils.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,32 @@ pub(crate) fn cargo_command(
2424
cmd
2525
}
2626

27+
pub(crate) fn hyperfine_command(
28+
warmup: u64,
29+
runs: u64,
30+
prepare: Option<Command>,
31+
a: Command,
32+
b: Command,
33+
) -> Command {
34+
let mut bench = Command::new("hyperfine");
35+
36+
if warmup != 0 {
37+
bench.arg("--warmup").arg(warmup.to_string());
38+
}
39+
40+
if runs != 0 {
41+
bench.arg("--runs").arg(runs.to_string());
42+
}
43+
44+
if let Some(prepare) = prepare {
45+
bench.arg("--prepare").arg(format!("{:?}", prepare));
46+
}
47+
48+
bench.arg(format!("{:?}", a)).arg(format!("{:?}", b));
49+
50+
bench
51+
}
52+
2753
#[track_caller]
2854
pub(crate) fn try_hard_link(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
2955
let src = src.as_ref();

0 commit comments

Comments
 (0)