Skip to content

Commit 6fcb096

Browse files
authored
Bench: Measure size of produced HTML files (#1057)
Recent changes have increased the size of the produced HTML files dramatically. Their size is very sensitive to change in the backend.
1 parent d32cd0c commit 6fcb096

File tree

1 file changed

+46
-38
lines changed

1 file changed

+46
-38
lines changed

doc/driver.mld

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -879,12 +879,36 @@ This last block analyze the running times so that they can be submitted to
879879
let rec compute_min_max_avg min_ max_ total count = function
880880
| [] -> (min_, max_, total /. float count, count)
881881
| hd :: tl ->
882-
compute_min_max_avg (min min_ hd) (max max_ hd) (total +. hd) (count + 1) tl
882+
compute_min_max_avg (min min_ hd) (max max_ hd) (total +. hd) (count + 1)
883+
tl
883884

884885
let compute_min_max_avg = function
885886
| [] -> assert false
886887
| hd :: tl -> compute_min_max_avg hd hd hd 1 tl
887888

889+
let compute_metric_int prefix suffix description values =
890+
let min, max, avg, count = compute_min_max_avg values in
891+
let min = int_of_float min in
892+
let max = int_of_float max in
893+
let avg = int_of_float avg in
894+
[
895+
`Assoc
896+
[
897+
("name", `String (prefix ^ "-total-" ^ suffix));
898+
("value", `Int count);
899+
("description", `String ("Number of " ^ description));
900+
];
901+
`Assoc
902+
[
903+
("name", `String (prefix ^ "-size-" ^ suffix));
904+
( "value",
905+
`Assoc [ ("min", `Int min); ("max", `Int max); ("avg", `Int avg) ] );
906+
("units", `String "b");
907+
("description", `String ("Size of " ^ description));
908+
("trend", `String "lower-is-better");
909+
];
910+
]
911+
888912
(** Analyze the running time of a command. *)
889913
let compute_metric_cmd cmd =
890914
let cmds = filter_commands cmd in
@@ -895,17 +919,14 @@ let compute_metric_cmd cmd =
895919
[
896920
("name", `String ("total-" ^ cmd));
897921
("value", `Int count);
898-
( "description",
899-
`String ("Number of time 'odoc " ^ cmd ^ "' has run.") );
922+
("description", `String ("Number of time 'odoc " ^ cmd ^ "' has run."));
900923
];
901924
`Assoc
902925
[
903926
("name", `String ("time-" ^ cmd));
904927
( "value",
905928
`Assoc
906-
[
907-
("min", `Float min); ("max", `Float max); ("avg", `Float avg);
908-
] );
929+
[ ("min", `Float min); ("max", `Float max); ("avg", `Float avg) ] );
909930
("units", `String "s");
910931
("description", `String ("Time taken by 'odoc " ^ cmd ^ "'"));
911932
("trend", `String "lower-is-better");
@@ -923,32 +944,21 @@ let compute_produced_cmd cmd =
923944
| None -> None
924945
in
925946
let sizes = List.filter_map output_file_size (filter_commands cmd) in
926-
let min, max, avg, count = compute_min_max_avg sizes in
927-
let min = int_of_float min in
928-
let max = int_of_float max in
929-
let avg = int_of_float avg in
930-
[
931-
`Assoc
932-
[
933-
("name", `String ("produced-total-" ^ cmd));
934-
("value", `Int count);
935-
( "description",
936-
`String ("Number of file produced by 'odoc " ^ cmd ^ "'") );
937-
];
938-
`Assoc
939-
[
940-
("name", `String ("produced-size-" ^ cmd));
941-
( "value",
942-
`Assoc
943-
[
944-
("min", `Int min); ("max", `Int max); ("avg", `Int avg);
945-
] );
946-
("units", `String "b");
947-
( "description",
948-
`String ("Size of file produced by 'odoc " ^ cmd ^ "'") );
949-
("trend", `String "lower-is-better");
950-
];
951-
]
947+
compute_metric_int "produced" cmd
948+
("files produced by 'odoc " ^ cmd ^ "'")
949+
sizes
950+
951+
(** Analyze the size of files outputed to the given directory. *)
952+
let compute_produced_tree cmd dir =
953+
let acc_file_sizes path acc =
954+
match Bos.OS.Path.stat path with
955+
| Ok st -> float st.Unix.st_size :: acc
956+
| Error _ -> acc
957+
in
958+
Bos.OS.Dir.fold_contents ~dotfiles:true ~elements:`Files acc_file_sizes []
959+
(Fpath.v dir)
960+
|> get_ok
961+
|> compute_metric_int "produced" cmd ("files produced by 'odoc " ^ cmd ^ "'")
952962

953963
(** Analyze the running time of the slowest commands. *)
954964
let compute_longest_cmd cmd =
@@ -962,15 +972,12 @@ let compute_longest_cmd cmd =
962972
("name", `String ("longest-" ^ cmd));
963973
( "value",
964974
`Assoc
965-
[
966-
("min", `Float min); ("max", `Float max); ("avg", `Float avg);
967-
] );
975+
[ ("min", `Float min); ("max", `Float max); ("avg", `Float avg) ] );
968976
("units", `String "s");
969977
( "description",
970978
`String
971-
(Printf.sprintf "Time taken by the %d longest calls to 'odoc %s'"
972-
k cmd)
973-
);
979+
(Printf.sprintf "Time taken by the %d longest calls to 'odoc %s'" k
980+
cmd) );
974981
("trend", `String "lower-is-better");
975982
];
976983
]
@@ -984,6 +991,7 @@ let metrics =
984991
@ compute_longest_cmd "link"
985992
@ compute_produced_cmd "compile"
986993
@ compute_produced_cmd "link"
994+
@ compute_produced_tree "html-generate" "html/"
987995

988996
let bench_results =
989997
`Assoc

0 commit comments

Comments
 (0)