5 use super::path::{Dirs, RelPath};
6 use super::prepare::GitRepo;
7 use super::rustc_info::get_file_name;
8 use super::utils::{hyperfine_command, is_ci, spawn_and_wait, CargoProject, Compiler};
10 pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
13 "804a7a21b9e673a482797aa289a18ed480e4d813",
17 // Use a separate target dir for the initial LLVM build to reduce unnecessary recompiles
18 pub(crate) static SIMPLE_RAYTRACER_LLVM: CargoProject =
19 CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer_llvm");
21 pub(crate) static SIMPLE_RAYTRACER: CargoProject =
22 CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer");
24 pub(crate) fn benchmark(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
25 benchmark_simple_raytracer(dirs, bootstrap_host_compiler);
28 fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
29 if std::process::Command::new("hyperfine").output().is_err() {
30 eprintln!("Hyperfine not installed");
31 eprintln!("Hint: Try `cargo install hyperfine` to install hyperfine");
32 std::process::exit(1);
35 eprintln!("[LLVM BUILD] simple-raytracer");
36 let build_cmd = SIMPLE_RAYTRACER_LLVM.build(bootstrap_host_compiler, dirs);
37 spawn_and_wait(build_cmd);
41 .join(&bootstrap_host_compiler.triple)
43 .join(get_file_name("main", "bin")),
44 RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_llvm", "bin")),
48 let run_runs = env::var("RUN_RUNS")
49 .unwrap_or(if is_ci() { "2" } else { "10" }.to_string())
53 eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
55 RelPath::DIST.to_path(dirs).join(get_file_name("cargo_clif", "bin").replace('_', "-"));
56 let manifest_path = SIMPLE_RAYTRACER.manifest_path(dirs);
57 let target_dir = SIMPLE_RAYTRACER.target_dir(dirs);
59 let clean_cmd = format!(
60 "cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
61 manifest_path = manifest_path.display(),
62 target_dir = target_dir.display(),
64 let llvm_build_cmd = format!(
65 "cargo build --manifest-path {manifest_path} --target-dir {target_dir}",
66 manifest_path = manifest_path.display(),
67 target_dir = target_dir.display(),
69 let clif_build_cmd = format!(
70 "{cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}",
71 cargo_clif = cargo_clif.display(),
72 manifest_path = manifest_path.display(),
73 target_dir = target_dir.display(),
77 hyperfine_command(1, run_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_cmd);
79 spawn_and_wait(bench_compile);
81 eprintln!("[BENCH RUN] ebobby/simple-raytracer");
83 target_dir.join("debug").join(get_file_name("main", "bin")),
84 RelPath::BUILD.to_path(dirs).join(get_file_name("raytracer_cg_clif", "bin")),
88 let mut bench_run = hyperfine_command(
92 Path::new(".").join(get_file_name("raytracer_cg_llvm", "bin")).to_str().unwrap(),
93 Path::new(".").join(get_file_name("raytracer_cg_clif", "bin")).to_str().unwrap(),
95 bench_run.current_dir(RelPath::BUILD.to_path(dirs));
96 spawn_and_wait(bench_run);