11use std:: env;
2+ use std:: io:: Write ;
23use std:: path:: Path ;
34
45use super :: path:: { Dirs , RelPath } ;
@@ -30,6 +31,12 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
3031
3132 let bench_runs = env:: var ( "BENCH_RUNS" ) . unwrap_or_else ( |_| "10" . to_string ( ) ) . parse ( ) . unwrap ( ) ;
3233
34+ let mut gha_step_summary = if let Ok ( file) = std:: env:: var ( "GITHUB_STEP_SUMMARY" ) {
35+ Some ( std:: fs:: OpenOptions :: new ( ) . append ( true ) . open ( file) . unwrap ( ) )
36+ } else {
37+ None
38+ } ;
39+
3340 eprintln ! ( "[BENCH COMPILE] ebobby/simple-raytracer" ) ;
3441 let cargo_clif = RelPath :: DIST
3542 . to_path ( dirs)
@@ -60,17 +67,28 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
6067 target_dir = target_dir. display( ) ,
6168 ) ;
6269
70+ let bench_compile_markdown = RelPath :: DIST . to_path ( dirs) . join ( "bench_compile.md" ) ;
71+
6372 let bench_compile = hyperfine_command (
6473 1 ,
6574 bench_runs,
6675 Some ( & clean_cmd) ,
6776 & [ & llvm_build_cmd, & clif_build_cmd, & clif_build_opt_cmd] ,
77+ & bench_compile_markdown,
6878 ) ;
6979
7080 spawn_and_wait ( bench_compile) ;
7181
82+ if let Some ( gha_step_summary) = gha_step_summary. as_mut ( ) {
83+ gha_step_summary. write_all ( b"# Compilation\n \n " ) . unwrap ( ) ;
84+ gha_step_summary. write_all ( & std:: fs:: read ( bench_compile_markdown) . unwrap ( ) ) . unwrap ( ) ;
85+ gha_step_summary. write_all ( b"\n " ) . unwrap ( ) ;
86+ }
87+
7288 eprintln ! ( "[BENCH RUN] ebobby/simple-raytracer" ) ;
7389
90+ let bench_run_markdown = RelPath :: DIST . to_path ( dirs) . join ( "bench_run.md" ) ;
91+
7492 let mut bench_run = hyperfine_command (
7593 0 ,
7694 bench_runs,
@@ -89,7 +107,14 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
89107 . to_str ( )
90108 . unwrap ( ) ,
91109 ] ,
110+ & bench_run_markdown,
92111 ) ;
93112 bench_run. current_dir ( RelPath :: BUILD . to_path ( dirs) ) ;
94113 spawn_and_wait ( bench_run) ;
114+
115+ if let Some ( gha_step_summary) = gha_step_summary. as_mut ( ) {
116+ gha_step_summary. write_all ( b"# Execution\n \n " ) . unwrap ( ) ;
117+ gha_step_summary. write_all ( & std:: fs:: read ( bench_run_markdown) . unwrap ( ) ) . unwrap ( ) ;
118+ gha_step_summary. write_all ( b"\n " ) . unwrap ( ) ;
119+ }
95120}
0 commit comments