about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-05-14 14:49:55 +0200
committerGitHub <noreply@github.com>2023-05-14 14:49:55 +0200
commitd16ba45fe459b7fb0508a5717e9f9762abf5d452 (patch)
tree24dd4f959951e138621b94ea5b220b005db44b57
parentd2a8023948697ab07ed9ec08fb87588b858d9439 (diff)
parenta43f08363e0983812fbbe68e8d91accf9496a1dd (diff)
downloadrust-d16ba45fe459b7fb0508a5717e9f9762abf5d452.tar.gz
rust-d16ba45fe459b7fb0508a5717e9f9762abf5d452.zip
Merge pull request #1373 from bjorn3/more_bench
Benchmark clif release builds with ./y.rs bench
-rw-r--r--build_system/bench.rs68
-rw-r--r--build_system/mod.rs2
-rw-r--r--build_system/utils.rs5
3 files changed, 28 insertions, 47 deletions
diff --git a/build_system/bench.rs b/build_system/bench.rs
index a9a851d0a8a..49f2954d57f 100644
--- a/build_system/bench.rs
+++ b/build_system/bench.rs
@@ -1,11 +1,10 @@
 use std::env;
-use std::fs;
 use std::path::Path;
 
 use super::path::{Dirs, RelPath};
 use super::prepare::GitRepo;
 use super::rustc_info::get_file_name;
-use super::utils::{hyperfine_command, spawn_and_wait, CargoProject, Compiler};
+use super::utils::{hyperfine_command, spawn_and_wait};
 
 static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
     "ebobby",
@@ -14,18 +13,11 @@ static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
     "<none>",
 );
 
-// Use a separate target dir for the initial LLVM build to reduce unnecessary recompiles
-static SIMPLE_RAYTRACER_LLVM: CargoProject =
-    CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer_llvm");
-
-static SIMPLE_RAYTRACER: CargoProject =
-    CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer");
-
-pub(crate) fn benchmark(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
-    benchmark_simple_raytracer(dirs, bootstrap_host_compiler);
+pub(crate) fn benchmark(dirs: &Dirs) {
+    benchmark_simple_raytracer(dirs);
 }
 
-fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
+fn benchmark_simple_raytracer(dirs: &Dirs) {
     if std::process::Command::new("hyperfine").output().is_err() {
         eprintln!("Hyperfine not installed");
         eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine");
@@ -34,33 +26,15 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
 
     if !SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).exists() {
         SIMPLE_RAYTRACER_REPO.fetch(dirs);
-        spawn_and_wait(SIMPLE_RAYTRACER.fetch(
-            &bootstrap_host_compiler.cargo,
-            &bootstrap_host_compiler.rustc,
-            dirs,
-        ));
     }
 
-    eprintln!("[LLVM BUILD] simple-raytracer");
-    let build_cmd = SIMPLE_RAYTRACER_LLVM.build(bootstrap_host_compiler, dirs);
-    spawn_and_wait(build_cmd);
-    fs::copy(
-        SIMPLE_RAYTRACER_LLVM
-            .target_dir(dirs)
-            .join(&bootstrap_host_compiler.triple)
-            .join("debug")
-            .join(get_file_name("main", "bin")),
-        RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_llvm", "bin")),
-    )
-    .unwrap();
-
     let bench_runs = env::var("BENCH_RUNS").unwrap_or_else(|_| "10".to_string()).parse().unwrap();
 
     eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
     let cargo_clif =
         RelPath::DIST.to_path(dirs).join(get_file_name("cargo_clif", "bin").replace('_', "-"));
-    let manifest_path = SIMPLE_RAYTRACER.manifest_path(dirs);
-    let target_dir = SIMPLE_RAYTRACER.target_dir(dirs);
+    let manifest_path = SIMPLE_RAYTRACER_REPO.source_dir().to_path(dirs).join("Cargo.toml");
+    let target_dir = RelPath::BUILD.join("simple_raytracer").to_path(dirs);
 
     let clean_cmd = format!(
         "RUSTC=rustc cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
@@ -68,35 +42,43 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
         target_dir = target_dir.display(),
     );
     let llvm_build_cmd = format!(
-        "RUSTC=rustc cargo build --manifest-path {manifest_path} --target-dir {target_dir}",
+        "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",
         manifest_path = manifest_path.display(),
         target_dir = target_dir.display(),
     );
     let clif_build_cmd = format!(
-        "RUSTC=rustc {cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}",
+        "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",
+        cargo_clif = cargo_clif.display(),
+        manifest_path = manifest_path.display(),
+        target_dir = target_dir.display(),
+    );
+    let clif_build_opt_cmd = format!(
+        "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",
         cargo_clif = cargo_clif.display(),
         manifest_path = manifest_path.display(),
         target_dir = target_dir.display(),
     );
 
-    let bench_compile =
-        hyperfine_command(1, bench_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_cmd);
+    let bench_compile = hyperfine_command(
+        1,
+        bench_runs,
+        Some(&clean_cmd),
+        &[&llvm_build_cmd, &clif_build_cmd, &clif_build_opt_cmd],
+    );
 
     spawn_and_wait(bench_compile);
 
     eprintln!("[BENCH RUN] ebobby/simple-raytracer");
-    fs::copy(
-        target_dir.join("debug").join(get_file_name("main", "bin")),
-        RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_clif", "bin")),
-    )
-    .unwrap();
 
     let mut bench_run = hyperfine_command(
         0,
         bench_runs,
         None,
-        Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(),
-        Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(),
+        &[
+            Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(),
+            Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(),
+            Path::new(".").join(get_file_name("raytracer_cg_clif_opt", "bin")).to_str().unwrap(),
+        ],
     );
     bench_run.current_dir(RelPath::BUILD.to_path(dirs));
     spawn_and_wait(bench_run);
diff --git a/build_system/mod.rs b/build_system/mod.rs
index e4ed9be23b7..b3293486c13 100644
--- a/build_system/mod.rs
+++ b/build_system/mod.rs
@@ -187,7 +187,7 @@ pub(crate) fn main() {
                 &bootstrap_host_compiler,
                 target_triple,
             );
-            bench::benchmark(&dirs, &bootstrap_host_compiler);
+            bench::benchmark(&dirs);
         }
     }
 }
diff --git a/build_system/utils.rs b/build_system/utils.rs
index abc5bab4942..8928ed7cd56 100644
--- a/build_system/utils.rs
+++ b/build_system/utils.rs
@@ -162,8 +162,7 @@ pub(crate) fn hyperfine_command(
     warmup: u64,
     runs: u64,
     prepare: Option<&str>,
-    a: &str,
-    b: &str,
+    cmds: &[&str],
 ) -> Command {
     let mut bench = Command::new("hyperfine");
 
@@ -179,7 +178,7 @@ pub(crate) fn hyperfine_command(
         bench.arg("--prepare").arg(prepare);
     }
 
-    bench.arg(a).arg(b);
+    bench.args(cmds);
 
     bench
 }