Skip to content

Commit

Permalink
add a benchmark for the Stream functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gasche committed Feb 16, 2022
1 parent 616a683 commit 874eaa6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bench/bench.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ let large_string_list =
in
`List strings

let streamable_string =
let buf = Buffer.create (large * 100) in
for i = 1 to large do
Printf.bprintf buf "%d\n" i
done;
Buffer.contents buf

let main () =
Command.run (Bench.make_command [
Bench.Test.create ~name:"JSON reading" (fun () ->
Expand All @@ -46,6 +53,13 @@ let main () =
Bench.Test.create ~name:"JSON writing assoc to channel" (fun () ->
Out_channel.with_file "/dev/null" ~f:(fun oc ->
ignore (Yojson.Safe.to_channel oc large_int_assoc)));
begin
let buf = Buffer.create 1000 in
Bench.Test.create ~name:"JSON stream roundtrip" (fun () ->
let stream = Yojson.Safe.stream_from_string ~buf streamable_string in
ignore (Yojson.Safe.stream_to_string ~buf stream)
)
end;
])

let () =
Expand Down

0 comments on commit 874eaa6

Please sign in to comment.