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

Commit a43f083

Browse files
committed
Benchmark clif release builds with ./y.rs bench
1 parent 88ae8fc commit a43f083

File tree

2 files changed

+22
-42
lines changed

2 files changed

+22
-42
lines changed

build_system/bench.rs

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use std::env;
2-
use std::fs;
32
use std::path::Path;
43

54
use super::path::{Dirs, RelPath};
65
use super::prepare::GitRepo;
76
use super::rustc_info::get_file_name;
8-
use super::utils::{hyperfine_command, spawn_and_wait, CargoProject, Compiler};
7+
use super::utils::{hyperfine_command, spawn_and_wait};
98

109
static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
1110
"ebobby",
@@ -14,18 +13,11 @@ static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
1413
"<none>",
1514
);
1615

17-
// Use a separate target dir for the initial LLVM build to reduce unnecessary recompiles
18-
static SIMPLE_RAYTRACER_LLVM: CargoProject =
19-
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer_llvm");
20-
21-
static SIMPLE_RAYTRACER: CargoProject =
22-
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer");
23-
24-
pub(crate) fn benchmark(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
25-
benchmark_simple_raytracer(dirs, bootstrap_host_compiler);
16+
pub(crate) fn benchmark(dirs: &Dirs) {
17+
benchmark_simple_raytracer(dirs);
2618
}
2719

28-
fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
20+
fn benchmark_simple_raytracer(dirs: &Dirs) {
2921
if std::process::Command::new("hyperfine").output().is_err() {
3022
eprintln!("Hyperfine not installed");
3123
eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine");
@@ -34,62 +26,49 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
3426

3527
if !SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).exists() {
3628
SIMPLE_RAYTRACER_REPO.fetch(dirs);
37-
spawn_and_wait(SIMPLE_RAYTRACER.fetch(
38-
&bootstrap_host_compiler.cargo,
39-
&bootstrap_host_compiler.rustc,
40-
dirs,
41-
));
4229
}
4330

44-
eprintln!("[LLVM BUILD] simple-raytracer");
45-
let build_cmd = SIMPLE_RAYTRACER_LLVM.build(bootstrap_host_compiler, dirs);
46-
spawn_and_wait(build_cmd);
47-
fs::copy(
48-
SIMPLE_RAYTRACER_LLVM
49-
.target_dir(dirs)
50-
.join(&bootstrap_host_compiler.triple)
51-
.join("debug")
52-
.join(get_file_name("main", "bin")),
53-
RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_llvm", "bin")),
54-
)
55-
.unwrap();
56-
5731
let bench_runs = env::var("BENCH_RUNS").unwrap_or_else(|_| "10".to_string()).parse().unwrap();
5832

5933
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
6034
let cargo_clif =
6135
RelPath::DIST.to_path(dirs).join(get_file_name("cargo_clif", "bin").replace('_', "-"));
62-
let manifest_path = SIMPLE_RAYTRACER.manifest_path(dirs);
63-
let target_dir = SIMPLE_RAYTRACER.target_dir(dirs);
36+
let manifest_path = SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).join("Cargo.toml");
37+
let target_dir = RelPath::BUILD.join("simple_raytracer").to_path(dirs);
6438

6539
let clean_cmd = format!(
6640
"RUSTC=rustc cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
6741
manifest_path = manifest_path.display(),
6842
target_dir = target_dir.display(),
6943
);
7044
let llvm_build_cmd = format!(
71-
"RUSTC=rustc cargo build --manifest-path {manifest_path} --target-dir {target_dir}",
45+
"RUSTC=rustc cargo build --manifest-path {manifest_path} --target-dir {target_dir} && (rm build/raytracer_cg_llvm || true) && ln build/simple_raytracer/debug/main build/raytracer_cg_llvm",
7246
manifest_path = manifest_path.display(),
7347
target_dir = target_dir.display(),
7448
);
7549
let clif_build_cmd = format!(
76-
"RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}",
50+
"RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir} && (rm build/raytracer_cg_clif || true) && ln build/simple_raytracer/debug/main build/raytracer_cg_clif",
51+
cargo_clif = cargo_clif.display(),
52+
manifest_path = manifest_path.display(),
53+
target_dir = target_dir.display(),
54+
);
55+
let clif_build_opt_cmd = format!(
56+
"RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir} --release && (rm build/raytracer_cg_clif_opt || true) && ln build/simple_raytracer/release/main build/raytracer_cg_clif_opt",
7757
cargo_clif = cargo_clif.display(),
7858
manifest_path = manifest_path.display(),
7959
target_dir = target_dir.display(),
8060
);
8161

82-
let bench_compile =
83-
hyperfine_command(1, bench_runs, Some(&clean_cmd), &[&llvm_build_cmd, &clif_build_cmd]);
62+
let bench_compile = hyperfine_command(
63+
1,
64+
bench_runs,
65+
Some(&clean_cmd),
66+
&[&llvm_build_cmd, &clif_build_cmd, &clif_build_opt_cmd],
67+
);
8468

8569
spawn_and_wait(bench_compile);
8670

8771
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
88-
fs::copy(
89-
target_dir.join("debug").join(get_file_name("main", "bin")),
90-
RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_clif", "bin")),
91-
)
92-
.unwrap();
9372

9473
let mut bench_run = hyperfine_command(
9574
0,
@@ -98,6 +77,7 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
9877
&[
9978
Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(),
10079
Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(),
80+
Path::new(".").join(get_file_name("raytracer_cg_clif_opt", "bin")).to_str().unwrap(),
10181
],
10282
);
10383
bench_run.current_dir(RelPath::BUILD.to_path(dirs));

build_system/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub(crate) fn main() {
187187
&bootstrap_host_compiler,
188188
target_triple,
189189
);
190-
bench::benchmark(&dirs, &bootstrap_host_compiler);
190+
bench::benchmark(&dirs);
191191
}
192192
}
193193
}

0 commit comments

Comments
 (0)