Skip to content

Commit 968dd54

Browse files
committed
Add -brief output mode
This is useful as the output mode when running a benchmark executable as a test and the JSON output is just too much.
1 parent 73d956a commit 968dd54

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Next release
22

3+
- Add `-brief` to show results in a concise human readable format (@polytypic)
34
- Add support for `wrap`ping the work without timing `wrap` itself (@polytypic)
45
- Add `-diff base.json` switch to diff against base results from file
56
(@polytypic)

bench/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ let () =
1010

1111
(test
1212
(name main)
13+
(action
14+
(run %{test} -brief))
1315
(libraries
1416
multicore-bench
1517
backoff

lib/cmd.ml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
type output = [ `JSON | `Brief | `Diff of string ]
2+
3+
let print_brief json =
4+
let open Data in
5+
json |> Results.parse
6+
|> Option.iter @@ fun (results : Results.t) ->
7+
results
8+
|> List.iter @@ fun (bench : Benchmark.t) ->
9+
Printf.printf "%s:\n" bench.name;
10+
bench.metrics
11+
|> List.iter @@ fun (metric : Metric.t) ->
12+
Printf.printf " %s:\n" metric.name;
13+
Printf.printf " %.2f %s\n" metric.value metric.units
14+
115
let print_diff base next =
216
let open Data in
317
Option.pair (Results.parse base) (Results.parse next)
@@ -49,12 +63,12 @@ let build_filter = function
4963
| exception Not_found -> false
5064
end
5165

52-
let run ~benchmarks ?(budgetf = 0.025) ?(filters = []) ?(debug = false) ?diff
53-
?(argv = Sys.argv) ?(flush = true) () =
66+
let run ~benchmarks ?(budgetf = 0.025) ?(filters = []) ?(debug = false)
67+
?(output = `JSON) ?(argv = Sys.argv) ?(flush = true) () =
5468
let budgetf = ref budgetf in
5569
let filters = ref filters in
5670
let debug = ref debug in
57-
let diff = ref diff in
71+
let output = ref output in
5872

5973
let rec specs =
6074
[
@@ -63,8 +77,11 @@ let run ~benchmarks ?(budgetf = 0.025) ?(filters = []) ?(debug = false) ?diff
6377
Arg.Set debug,
6478
"\t Print progress information to help debugging" );
6579
( "-diff",
66-
Arg.String (fun path -> diff := Some path),
80+
Arg.String (fun path -> output := `Diff path),
6781
"path.json\t Show diff against specified base results" );
82+
( "-brief",
83+
Arg.Unit (fun () -> output := `Brief),
84+
"\t Show brief human readable results." );
6885
("-help", Unit help, "\t Show this help message");
6986
("--help", Unit help, "\t Show this help message");
7087
]
@@ -100,9 +117,10 @@ let run ~benchmarks ?(budgetf = 0.025) ?(filters = []) ?(debug = false) ?diff
100117
in
101118

102119
begin
103-
match !diff with
104-
| None -> Yojson.Safe.pretty_print ~std:true Format.std_formatter results
105-
| Some fname -> print_diff (Yojson.Safe.from_file fname) results
120+
match !output with
121+
| `JSON -> Yojson.Safe.pretty_print ~std:true Format.std_formatter results
122+
| `Brief -> print_brief results
123+
| `Diff fname -> print_diff (Yojson.Safe.from_file fname) results
106124
end;
107125

108126
if flush then Format.print_flush ()

lib/multicore_bench.mli

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,23 @@ end
143143
module Cmd : sig
144144
(** Command line interface for a benchmark executable. *)
145145

146+
type output =
147+
[ `JSON
148+
(** [`JSON] gives the JSON output for
149+
{{:https://github.com/ocurrent/current-bench}current-bench}. *)
150+
| `Brief (** [`Brief] gives concise human readable output. *)
151+
| `Diff of string
152+
(** [`Diff "path.json"] gives concise human readable diff against results
153+
stored in specified [path.json] file. *)
154+
]
155+
(** Specifies the output format. *)
156+
146157
val run :
147158
benchmarks:(string * Suite.t) list ->
148159
?budgetf:float ->
149160
?filters:string list ->
150161
?debug:bool ->
151-
?diff:string ->
162+
?output:output ->
152163
?argv:string array ->
153164
?flush:bool ->
154165
unit ->
@@ -169,8 +180,7 @@ module Cmd : sig
169180
- [~debug]: Print progress information to help debugging. Defaults to
170181
[false].
171182
172-
- [~diff]: Name of JSON file of results to show diff against. Defaults to
173-
[None].
183+
- [~output]: Output mode. Defaults to [`JSON].
174184
175185
- [~argv]: Array of command line arguments. Defaults to [Sys.argv].
176186

0 commit comments

Comments
 (0)