1
1
use std:: env;
2
- use std:: fs;
3
2
use std:: path:: Path ;
4
3
5
4
use super :: path:: { Dirs , RelPath } ;
6
5
use super :: prepare:: GitRepo ;
7
6
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} ;
9
8
10
9
static SIMPLE_RAYTRACER_REPO : GitRepo = GitRepo :: github (
11
10
"ebobby" ,
@@ -14,18 +13,11 @@ static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
14
13
"<none>" ,
15
14
) ;
16
15
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) ;
26
18
}
27
19
28
- fn benchmark_simple_raytracer ( dirs : & Dirs , bootstrap_host_compiler : & Compiler ) {
20
+ fn benchmark_simple_raytracer ( dirs : & Dirs ) {
29
21
if std:: process:: Command :: new ( "hyperfine" ) . output ( ) . is_err ( ) {
30
22
eprintln ! ( "Hyperfine not installed" ) ;
31
23
eprintln ! ( "Hint: Try `cargo install hyperfine` to install hyperfine" ) ;
@@ -34,69 +26,59 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
34
26
35
27
if !SIMPLE_RAYTRACER_REPO . source_dir ( ) . to_path ( dirs) . exists ( ) {
36
28
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
- ) ) ;
42
29
}
43
30
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
-
57
31
let bench_runs = env:: var ( "BENCH_RUNS" ) . unwrap_or_else ( |_| "10" . to_string ( ) ) . parse ( ) . unwrap ( ) ;
58
32
59
33
eprintln ! ( "[BENCH COMPILE] ebobby/simple-raytracer" ) ;
60
34
let cargo_clif =
61
35
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) ;
64
38
65
39
let clean_cmd = format ! (
66
40
"RUSTC=rustc cargo clean --manifest-path {manifest_path} --target-dir {target_dir}" ,
67
41
manifest_path = manifest_path. display( ) ,
68
42
target_dir = target_dir. display( ) ,
69
43
) ;
70
44
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 " ,
72
46
manifest_path = manifest_path. display( ) ,
73
47
target_dir = target_dir. display( ) ,
74
48
) ;
75
49
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" ,
77
57
cargo_clif = cargo_clif. display( ) ,
78
58
manifest_path = manifest_path. display( ) ,
79
59
target_dir = target_dir. display( ) ,
80
60
) ;
81
61
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
+ ) ;
84
68
85
69
spawn_and_wait ( bench_compile) ;
86
70
87
71
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 ( ) ;
93
72
94
73
let mut bench_run = hyperfine_command (
95
74
0 ,
96
75
bench_runs,
97
76
None ,
98
- Path :: new ( "." ) . join ( get_file_name ( "raytracer_cg_llvm" , "bin" ) ) . to_str ( ) . unwrap ( ) ,
99
- Path :: new ( "." ) . join ( get_file_name ( "raytracer_cg_clif" , "bin" ) ) . to_str ( ) . unwrap ( ) ,
77
+ & [
78
+ Path :: new ( "." ) . join ( get_file_name ( "raytracer_cg_llvm" , "bin" ) ) . to_str ( ) . unwrap ( ) ,
79
+ 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 ( ) ,
81
+ ] ,
100
82
) ;
101
83
bench_run. current_dir ( RelPath :: BUILD . to_path ( dirs) ) ;
102
84
spawn_and_wait ( bench_run) ;
0 commit comments