Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of notty for formatting benchmark results #71

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions bench/bechamel_csv/bechamel_csv.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
open Bechamel

let pad width v =
let padding = String.make (width - String.length v) ' ' in
padding ^ v

let pp_row ~width f data =
data |> List.iteri (fun i v ->
if i > 0 then Fmt.comma f ();
Fmt.pf f "%s" (pad width.(i) v)
)

let pp f results =
let results = Hashtbl.to_seq results |> Array.of_seq in
Array.sort (fun (n1, _) (n2, _) -> String.compare n1 n2) results; (* Sort columns *)
let rows = snd results.(0) |> Hashtbl.to_seq |> Seq.map fst |> Array.of_seq in
let width = Array.make (Array.length results + 1) 0 in
width.(0) <- String.length "name, ";
results |> Array.iteri (fun i (name, _) -> width.(i + 1) <- String.length name + 2);
Array.sort String.compare rows;
let rows =
rows |> Array.map (fun name ->
width.(0) <- max width.(0) (String.length name + 2);
let values =
results |> Array.mapi (fun i (_, col) ->
let v =
match Hashtbl.find col name |> Analyze.OLS.estimates with
| Some [v] -> Printf.sprintf "%f" v
| _ -> assert false
in
width.(i + 1) <- max width.(i + 1) (String.length v + 2);
v
)
in
name, values
)
in
let metrics = Array.to_list results |> List.map fst in
let headings = List.mapi (fun i v -> pad width.(i) v) ("name" :: metrics) in
Fmt.pf f "@[<v>@[<h>%a@]" Fmt.(list ~sep:comma string) headings;
rows |> Array.iter (fun (name, data) ->
Fmt.pf f "@,@[<h>%a@]" (pp_row ~width) (name :: Array.to_list data);
);
Fmt.pf f "@]"
2 changes: 2 additions & 0 deletions bench/bechamel_csv/bechamel_csv.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
val pp : (string, (string, Bechamel.Analyze.OLS.t) Stdlib.Hashtbl.t) Stdlib.Hashtbl.t Fmt.t
(** [pp] formats the results of {!Bechamel.Analyze.merge} as a CSV table. *)
3 changes: 3 additions & 0 deletions bench/bechamel_csv/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(library
(name bechamel_csv)
(libraries bechamel fmt))
17 changes: 1 addition & 16 deletions tests/cptest.ml → bench/cptest.ml
Original file line number Diff line number Diff line change
@@ -73,20 +73,5 @@ let benchmark () =
(results, raw_results)

let () =
List.iter
(fun v -> Bechamel_notty.Unit.add v (Measure.unit v))
Instance.[ minor_allocated; major_allocated; monotonic_clock ]

let img (window, results) =
Bechamel_notty.Multiple.image_of_ols_results ~rect:window
~predictor:Measure.run results

open Notty_unix

let () =
let window =
match winsize Unix.stdout with
| Some (w, h) -> { Bechamel_notty.w; h }
| None -> { Bechamel_notty.w = 80; h = 1 } in
let results, _ = benchmark () in
img (window, results) |> eol |> output_image
Fmt.pr "%a@." Bechamel_csv.pp results
13 changes: 12 additions & 1 deletion bench/dune
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
(executable
(name main)
(modules main)
(libraries uring bechamel bechamel-notty notty.unix))
(libraries uring bechamel bechamel_csv))

(executable
(name readv)
(modules readv)
(libraries uring))

(executable
(name cptest)
(modules cptest)
(libraries urcp_fixed_lib urcp_lib lwtcp_lib uring bechamel bechamel_csv))

(rule
(alias runbenchmark)
(package uring)
(action
(run ./cptest.exe)))
12 changes: 2 additions & 10 deletions bench/main.ml
Original file line number Diff line number Diff line change
@@ -31,14 +31,6 @@ let benchmark () =
List.map (fun i -> Analyze.all ols i raw_results) metrics
|> Analyze.merge ols metrics

let rect =
match Notty_unix.winsize Unix.stdout with
| Some (w, h) -> { Bechamel_notty.w; h }
| None -> { Bechamel_notty.w = 80; h = 1 }

let () =
List.iter (fun v -> Bechamel_notty.Unit.add v (Measure.unit v)) metrics;
benchmark ()
|> Bechamel_notty.Multiple.image_of_ols_results ~rect ~predictor:Measure.run
|> Notty_unix.eol
|> Notty_unix.output_image
let results = benchmark () in
Fmt.pr "@[<v>%a@]@." Bechamel_csv.pp results
2 changes: 0 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
@@ -17,8 +17,6 @@
(ocaml (>= 4.12.0))
dune-configurator
(lwt (and :with-test (>= 5.0.0)))
(notty (and (>= 0.2.2) :with-test))
(bechamel-notty (and (>= 0.1.0) :with-test))
(bechamel (and (>= 0.1.0) :with-test))
(logs (and :with-test (>= 0.5.0)))
(cmdliner (and :with-test (>= 1.1.0)))
8 changes: 1 addition & 7 deletions tests/dune
Original file line number Diff line number Diff line change
@@ -34,12 +34,6 @@
(modules poll_add)
(libraries unix uring logs logs.fmt))

(executable
(name cptest)
(modules cptest)
(libraries urcp_fixed_lib urcp_lib lwtcp_lib uring bechamel notty.unix
bechamel-notty))

(rule
(alias runtest)
(package uring)
@@ -50,7 +44,7 @@
(package uring)
(deps urcp.exe)
(action
(run ./cptest.exe ./urcp.exe)))
(run ./urcp.exe)))

(mdx
(deps (package uring)))
2 changes: 0 additions & 2 deletions uring.opam
Original file line number Diff line number Diff line change
@@ -15,8 +15,6 @@ depends: [
"ocaml" {>= "4.12.0"}
"dune-configurator"
"lwt" {with-test & >= "5.0.0"}
"notty" {>= "0.2.2" & with-test}
"bechamel-notty" {>= "0.1.0" & with-test}
"bechamel" {>= "0.1.0" & with-test}
"logs" {with-test & >= "0.5.0"}
"cmdliner" {with-test & >= "1.1.0"}