Skip to content

Commit 04cabc7

Browse files
committed
Output JSON lazily
1 parent 60768c9 commit 04cabc7

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

tests/syntax_benchmarks/Benchmark.ml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ module Benchmarks : sig
183183
val run : unit -> unit
184184
end = struct
185185
type action = Parse | Print
186+
186187
let string_of_action action =
187188
match action with
188189
| Parse -> "Parse"
@@ -196,7 +197,7 @@ end = struct
196197

197198
let data_dir = "tests/syntax_benchmarks/data"
198199

199-
let benchmark filename action =
200+
let benchmark (filename, action) =
200201
let path = Filename.concat data_dir filename in
201202
let src = IO.read_file path in
202203
let name = string_of_action action ^ " " ^ filename in
@@ -223,20 +224,25 @@ end = struct
223224
Benchmark.launch b;
224225
Benchmark.report b
225226

227+
let specs =
228+
[
229+
("RedBlackTree.res", Parse);
230+
("RedBlackTree.res", Print);
231+
("RedBlackTreeNoComments.res", Print);
232+
("Napkinscript.res", Parse);
233+
("Napkinscript.res", Print);
234+
("HeroGraphic.res", Parse);
235+
("HeroGraphic.res", Print);
236+
]
237+
226238
let run () =
227-
let results =
228-
List.flatten
229-
[
230-
benchmark "RedBlackTree.res" Parse;
231-
benchmark "RedBlackTree.res" Print;
232-
benchmark "RedBlackTreeNoComments.res" Print;
233-
benchmark "Napkinscript.res" Parse;
234-
benchmark "Napkinscript.res" Print;
235-
benchmark "HeroGraphic.res" Parse;
236-
benchmark "HeroGraphic.res" Print;
237-
]
238-
in
239-
print_endline (Yojson.pretty_to_string (`List results))
239+
List.to_seq specs
240+
|> Seq.flat_map (fun spec -> benchmark spec |> List.to_seq)
241+
|> Seq.iteri (fun i json ->
242+
print_endline (if i == 0 then "[" else ",");
243+
print_string (Yojson.to_string json));
244+
print_newline ();
245+
print_endline "]"
240246
end
241247

242248
let () = Benchmarks.run ()

0 commit comments

Comments
 (0)