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
+
1
15
let print_diff base next =
2
16
let open Data in
3
17
Option. pair (Results. parse base) (Results. parse next)
@@ -49,12 +63,12 @@ let build_filter = function
49
63
| exception Not_found -> false
50
64
end
51
65
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 ) () =
54
68
let budgetf = ref budgetf in
55
69
let filters = ref filters in
56
70
let debug = ref debug in
57
- let diff = ref diff in
71
+ let output = ref output in
58
72
59
73
let rec specs =
60
74
[
@@ -63,8 +77,11 @@ let run ~benchmarks ?(budgetf = 0.025) ?(filters = []) ?(debug = false) ?diff
63
77
Arg. Set debug,
64
78
" \t Print progress information to help debugging" );
65
79
( " -diff" ,
66
- Arg. String (fun path -> diff := Some path),
80
+ Arg. String (fun path -> output := `Diff path),
67
81
" path.json\t Show diff against specified base results" );
82
+ ( " -brief" ,
83
+ Arg. Unit (fun () -> output := `Brief ),
84
+ " \t Show brief human readable results." );
68
85
(" -help" , Unit help, " \t Show this help message" );
69
86
(" --help" , Unit help, " \t Show this help message" );
70
87
]
@@ -100,9 +117,10 @@ let run ~benchmarks ?(budgetf = 0.025) ?(filters = []) ?(debug = false) ?diff
100
117
in
101
118
102
119
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
106
124
end ;
107
125
108
126
if flush then Format. print_flush ()
0 commit comments