2023-01-05 11:57:35 -06:00
|
|
|
use std::env;
|
|
|
|
use std::fs;
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
use super::path::{Dirs, RelPath};
|
|
|
|
use super::prepare::GitRepo;
|
2023-01-15 08:14:13 -06:00
|
|
|
use super::rustc_info::get_file_name;
|
2023-01-13 05:41:40 -06:00
|
|
|
use super::utils::{hyperfine_command, is_ci, spawn_and_wait, CargoProject, Compiler};
|
2023-01-05 11:57:35 -06:00
|
|
|
|
2023-01-27 12:44:19 -06:00
|
|
|
static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
|
2023-01-05 11:57:35 -06:00
|
|
|
"ebobby",
|
|
|
|
"simple-raytracer",
|
|
|
|
"804a7a21b9e673a482797aa289a18ed480e4d813",
|
|
|
|
"<none>",
|
|
|
|
);
|
|
|
|
|
2023-01-13 05:41:40 -06:00
|
|
|
// Use a separate target dir for the initial LLVM build to reduce unnecessary recompiles
|
2023-01-27 12:44:19 -06:00
|
|
|
static SIMPLE_RAYTRACER_LLVM: CargoProject =
|
2023-01-13 05:41:40 -06:00
|
|
|
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer_llvm");
|
|
|
|
|
2023-01-27 12:44:19 -06:00
|
|
|
static SIMPLE_RAYTRACER: CargoProject =
|
2023-01-05 11:57:35 -06:00
|
|
|
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer");
|
|
|
|
|
2023-01-14 06:53:33 -06:00
|
|
|
pub(crate) fn benchmark(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
|
|
|
|
benchmark_simple_raytracer(dirs, bootstrap_host_compiler);
|
2023-01-05 11:57:35 -06:00
|
|
|
}
|
|
|
|
|
2023-01-14 06:53:33 -06:00
|
|
|
fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
|
2023-01-05 11:57:35 -06:00
|
|
|
if std::process::Command::new("hyperfine").output().is_err() {
|
|
|
|
eprintln!("Hyperfine not installed");
|
|
|
|
eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine");
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
|
2023-01-27 12:44:19 -06:00
|
|
|
SIMPLE_RAYTRACER_REPO.fetch(dirs);
|
|
|
|
spawn_and_wait(SIMPLE_RAYTRACER.fetch(
|
|
|
|
&bootstrap_host_compiler.cargo,
|
|
|
|
&bootstrap_host_compiler.rustc,
|
|
|
|
dirs,
|
|
|
|
));
|
|
|
|
|
2023-01-13 05:41:40 -06:00
|
|
|
eprintln!("[LLVM BUILD] simple-raytracer");
|
2023-01-14 06:53:33 -06:00
|
|
|
let build_cmd = SIMPLE_RAYTRACER_LLVM.build(bootstrap_host_compiler, dirs);
|
2023-01-13 05:41:40 -06:00
|
|
|
spawn_and_wait(build_cmd);
|
|
|
|
fs::copy(
|
|
|
|
SIMPLE_RAYTRACER_LLVM
|
|
|
|
.target_dir(dirs)
|
2023-01-14 06:53:33 -06:00
|
|
|
.join(&bootstrap_host_compiler.triple)
|
2023-01-13 05:41:40 -06:00
|
|
|
.join("debug")
|
|
|
|
.join(get_file_name("main", "bin")),
|
|
|
|
RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_llvm", "bin")),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
2023-01-05 11:57:35 -06:00
|
|
|
let run_runs = env::var("RUN_RUNS")
|
|
|
|
.unwrap_or(if is_ci() { "2" } else { "10" }.to_string())
|
|
|
|
.parse()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
|
2023-01-15 08:14:13 -06:00
|
|
|
let cargo_clif =
|
|
|
|
RelPath::DIST.to_path(dirs).join(get_file_name("cargo_clif", "bin").replace('_', "-"));
|
2023-01-05 11:57:35 -06:00
|
|
|
let manifest_path = SIMPLE_RAYTRACER.manifest_path(dirs);
|
|
|
|
let target_dir = SIMPLE_RAYTRACER.target_dir(dirs);
|
|
|
|
|
|
|
|
let clean_cmd = format!(
|
|
|
|
"cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
|
|
|
|
manifest_path = manifest_path.display(),
|
|
|
|
target_dir = target_dir.display(),
|
|
|
|
);
|
|
|
|
let llvm_build_cmd = format!(
|
|
|
|
"cargo build --manifest-path {manifest_path} --target-dir {target_dir}",
|
|
|
|
manifest_path = manifest_path.display(),
|
|
|
|
target_dir = target_dir.display(),
|
|
|
|
);
|
|
|
|
let clif_build_cmd = format!(
|
|
|
|
"{cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}",
|
|
|
|
cargo_clif = cargo_clif.display(),
|
|
|
|
manifest_path = manifest_path.display(),
|
|
|
|
target_dir = target_dir.display(),
|
|
|
|
);
|
|
|
|
|
|
|
|
let bench_compile =
|
|
|
|
hyperfine_command(1, run_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_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,
|
|
|
|
run_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(),
|
|
|
|
);
|
|
|
|
bench_run.current_dir(RelPath::BUILD.to_path(dirs));
|
|
|
|
spawn_and_wait(bench_run);
|
|
|
|
}
|