Skip to content

Commit c302549

Browse files
authored
Merge pull request #71 from talex5/nonotty
Remove use of notty for formatting benchmark results
2 parents bf83ebc + fd59d7c commit c302549

File tree

9 files changed

+65
-38
lines changed

9 files changed

+65
-38
lines changed

bench/bechamel_csv/bechamel_csv.ml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
open Bechamel
2+
3+
let pad width v =
4+
let padding = String.make (width - String.length v) ' ' in
5+
padding ^ v
6+
7+
let pp_row ~width f data =
8+
data |> List.iteri (fun i v ->
9+
if i > 0 then Fmt.comma f ();
10+
Fmt.pf f "%s" (pad width.(i) v)
11+
)
12+
13+
let pp f results =
14+
let results = Hashtbl.to_seq results |> Array.of_seq in
15+
Array.sort (fun (n1, _) (n2, _) -> String.compare n1 n2) results; (* Sort columns *)
16+
let rows = snd results.(0) |> Hashtbl.to_seq |> Seq.map fst |> Array.of_seq in
17+
let width = Array.make (Array.length results + 1) 0 in
18+
width.(0) <- String.length "name, ";
19+
results |> Array.iteri (fun i (name, _) -> width.(i + 1) <- String.length name + 2);
20+
Array.sort String.compare rows;
21+
let rows =
22+
rows |> Array.map (fun name ->
23+
width.(0) <- max width.(0) (String.length name + 2);
24+
let values =
25+
results |> Array.mapi (fun i (_, col) ->
26+
let v =
27+
match Hashtbl.find col name |> Analyze.OLS.estimates with
28+
| Some [v] -> Printf.sprintf "%f" v
29+
| _ -> assert false
30+
in
31+
width.(i + 1) <- max width.(i + 1) (String.length v + 2);
32+
v
33+
)
34+
in
35+
name, values
36+
)
37+
in
38+
let metrics = Array.to_list results |> List.map fst in
39+
let headings = List.mapi (fun i v -> pad width.(i) v) ("name" :: metrics) in
40+
Fmt.pf f "@[<v>@[<h>%a@]" Fmt.(list ~sep:comma string) headings;
41+
rows |> Array.iter (fun (name, data) ->
42+
Fmt.pf f "@,@[<h>%a@]" (pp_row ~width) (name :: Array.to_list data);
43+
);
44+
Fmt.pf f "@]"

bench/bechamel_csv/bechamel_csv.mli

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
val pp : (string, (string, Bechamel.Analyze.OLS.t) Stdlib.Hashtbl.t) Stdlib.Hashtbl.t Fmt.t
2+
(** [pp] formats the results of {!Bechamel.Analyze.merge} as a CSV table. *)

bench/bechamel_csv/dune

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(library
2+
(name bechamel_csv)
3+
(libraries bechamel fmt))

tests/cptest.ml bench/cptest.ml

+1-16
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,5 @@ let benchmark () =
7373
(results, raw_results)
7474

7575
let () =
76-
List.iter
77-
(fun v -> Bechamel_notty.Unit.add v (Measure.unit v))
78-
Instance.[ minor_allocated; major_allocated; monotonic_clock ]
79-
80-
let img (window, results) =
81-
Bechamel_notty.Multiple.image_of_ols_results ~rect:window
82-
~predictor:Measure.run results
83-
84-
open Notty_unix
85-
86-
let () =
87-
let window =
88-
match winsize Unix.stdout with
89-
| Some (w, h) -> { Bechamel_notty.w; h }
90-
| None -> { Bechamel_notty.w = 80; h = 1 } in
9176
let results, _ = benchmark () in
92-
img (window, results) |> eol |> output_image
77+
Fmt.pr "%a@." Bechamel_csv.pp results

bench/dune

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
(executable
22
(name main)
33
(modules main)
4-
(libraries uring bechamel bechamel-notty notty.unix))
4+
(libraries uring bechamel bechamel_csv))
55

66
(executable
77
(name readv)
88
(modules readv)
99
(libraries uring))
10+
11+
(executable
12+
(name cptest)
13+
(modules cptest)
14+
(libraries urcp_fixed_lib urcp_lib lwtcp_lib uring bechamel bechamel_csv))
15+
16+
(rule
17+
(alias runbenchmark)
18+
(package uring)
19+
(action
20+
(run ./cptest.exe)))

bench/main.ml

+2-10
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ let benchmark () =
3131
List.map (fun i -> Analyze.all ols i raw_results) metrics
3232
|> Analyze.merge ols metrics
3333

34-
let rect =
35-
match Notty_unix.winsize Unix.stdout with
36-
| Some (w, h) -> { Bechamel_notty.w; h }
37-
| None -> { Bechamel_notty.w = 80; h = 1 }
38-
3934
let () =
40-
List.iter (fun v -> Bechamel_notty.Unit.add v (Measure.unit v)) metrics;
41-
benchmark ()
42-
|> Bechamel_notty.Multiple.image_of_ols_results ~rect ~predictor:Measure.run
43-
|> Notty_unix.eol
44-
|> Notty_unix.output_image
35+
let results = benchmark () in
36+
Fmt.pr "@[<v>%a@]@." Bechamel_csv.pp results

dune-project

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
(ocaml (>= 4.12.0))
1818
dune-configurator
1919
(lwt (and :with-test (>= 5.0.0)))
20-
(notty (and (>= 0.2.2) :with-test))
21-
(bechamel-notty (and (>= 0.1.0) :with-test))
2220
(bechamel (and (>= 0.1.0) :with-test))
2321
(logs (and :with-test (>= 0.5.0)))
2422
(cmdliner (and :with-test (>= 1.1.0)))

tests/dune

+1-7
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
(modules poll_add)
3535
(libraries unix uring logs logs.fmt))
3636

37-
(executable
38-
(name cptest)
39-
(modules cptest)
40-
(libraries urcp_fixed_lib urcp_lib lwtcp_lib uring bechamel notty.unix
41-
bechamel-notty))
42-
4337
(rule
4438
(alias runtest)
4539
(package uring)
@@ -50,7 +44,7 @@
5044
(package uring)
5145
(deps urcp.exe)
5246
(action
53-
(run ./cptest.exe ./urcp.exe)))
47+
(run ./urcp.exe)))
5448

5549
(mdx
5650
(deps (package uring)))

uring.opam

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ depends: [
1515
"ocaml" {>= "4.12.0"}
1616
"dune-configurator"
1717
"lwt" {with-test & >= "5.0.0"}
18-
"notty" {>= "0.2.2" & with-test}
19-
"bechamel-notty" {>= "0.1.0" & with-test}
2018
"bechamel" {>= "0.1.0" & with-test}
2119
"logs" {with-test & >= "0.5.0"}
2220
"cmdliner" {with-test & >= "1.1.0"}

0 commit comments

Comments
 (0)