Skip to content

Commit 47b8477

Browse files
authored
Benchmarks: report generated code size (#1936)
1 parent 2b79e39 commit 47b8477

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

benchmarks/benchmark-fiat-crypto/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ bench:
1111
@date -u +"%FT%TZ - $(NAME): done"
1212

1313
perform: bedrock2_fiat_crypto.byte
14-
/usr/bin/time -f "%E %R" $(COMPILER) --debug times --source-map $(EXTRA_ARGS) $< 2>&1 | \
15-
ocaml -I +str str.cma ../utils/compilation_metrics.ml $(COMPILER) $(NAME) | \
14+
/usr/bin/time -f "%E %R" $(COMPILER) --debug times --source-map $(EXTRA_ARGS) $< -o out.js 2>&1 | \
15+
ocaml -I +str str.cma ../utils/compilation_metrics.ml $(COMPILER) $(NAME) out.js | \
1616
sh ../utils/aggregate.sh $(KIND)
1717

1818
bedrock2_fiat_crypto.byte: bedrock2_fiat_crypto.ml

benchmarks/benchmark-ocamlc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ARGS=ml/*.ml ml/*.ml ml/*.ml ml/*.ml ml/*.ml ml/*.ml ml/*.ml ml/*.ml
1515

1616
perform:
1717
/usr/bin/time -f "%E %R" $(COMPILER) --debug times --opt 2 --pretty `which ocamlc.byte` -o $(SCRIPT) 2>&1 | \
18-
ocaml -I +str str.cma ../utils/compilation_metrics.ml $(COMPILER) $(NAME) | \
18+
ocaml -I +str str.cma ../utils/compilation_metrics.ml $(COMPILER) $(NAME) $(SCRIPT) | \
1919
sh ../utils/aggregate.sh $(KIND)
2020
/usr/bin/time -f '{"compiler": "$(COMPILER)", "time":"%E"}' node $(SCRIPT) -c $(ARGS) 2>&1 | \
2121
sh ../utils/format_metrics.sh exec | \

benchmarks/benchmark-partial-render-table/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bench:
1616
perform:
1717
/usr/bin/time -f "%E %R" $(COMPILER) --debug times --opt 2 --pretty main.bc-for-jsoo -o out.js 2>&1 | \
1818
tee /dev/stderr | \
19-
ocaml -I +str str.cma ../utils/compilation_metrics.ml $(COMPILER) "$(NAME)" | \
19+
ocaml -I +str str.cma ../utils/compilation_metrics.ml $(COMPILER) "$(NAME)" out.js | \
2020
sh ../utils/aggregate.sh $(KIND)
2121
node $(SCRIPT) | \
2222
tee /dev/stderr | \

benchmarks/utils/compilation_metrics.ml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
let compiler = Sys.argv.(1)
2+
3+
let benchmark_name = Sys.argv.(2)
4+
5+
let output = Sys.argv.(3)
6+
17
let time_re = Str.regexp "^ \\([^ ].*\\): \\([0-9.]+\\)$"
28

39
let () =
@@ -14,22 +20,38 @@ let () =
1420
last_line := l
1521
done
1622
with End_of_file -> ());
23+
let file_size =
24+
let file =
25+
match compiler with
26+
| "js_of_ocaml" -> output
27+
| "wasm_of_ocaml" ->
28+
let dir = Filename.chop_suffix output ".js" ^ ".assets" in
29+
let contents = Sys.readdir dir in
30+
let code =
31+
Array.find_opt (fun nm -> Filename.check_suffix nm ".wasm") contents
32+
in
33+
Filename.concat dir (Option.get code)
34+
| _ -> assert false
35+
in
36+
In_channel.(with_open_bin file length)
37+
in
1738
let l = Hashtbl.fold (fun nm v rem -> (nm, v) :: rem) times [] in
1839
let l = List.filter (fun (_, v) -> v > 0.2) l in
1940
let l = List.map (fun (nm, v) -> "Compilation phases/" ^ nm, "s", v) l in
2041
let l' =
2142
Scanf.sscanf !last_line "%f:%f %f" (fun m s mem ->
2243
[ "Compilation time", "s", (m *. 60.) +. s
2344
; "Compilation memory usage", "KiB", mem
45+
; "Code size", "KiB", float (Int64.to_int file_size / 1024)
2446
])
2547
in
2648
Format.printf
2749
{|{ "name": "%s",
2850
"results":
2951
[ { "name": "%s",
3052
"metrics":@.|}
31-
(String.capitalize_ascii Sys.argv.(1))
32-
Sys.argv.(2);
53+
(String.capitalize_ascii compiler)
54+
benchmark_name;
3355
Format.printf " [ @[";
3456
List.iteri
3557
(fun i (nm, u, v) ->

0 commit comments

Comments
 (0)