From 874eaa69637963fd8802359bed7081a9c1c0fe85 Mon Sep 17 00:00:00 2001 From: Gabriel Scherer Date: Wed, 9 Feb 2022 13:43:28 +0100 Subject: [PATCH] add a benchmark for the Stream functions --- bench/bench.ml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bench/bench.ml b/bench/bench.ml index 349a44b4..99b6fabe 100644 --- a/bench/bench.ml +++ b/bench/bench.ml @@ -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 () -> @@ -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 () =