Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ocamlformat on the part of the codebase that doesn't use CPPO #153

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Introduced ocamlformat
3101ec295fbc791a1e9384f50178846198a607c7
2 changes: 2 additions & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version=0.24.1
profile=conventional
6 changes: 6 additions & 0 deletions .ocamlformat-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# disable ocamlformat on files that are processed by CPPO
lib/*.cppo.ml*
lib/monomorphic.ml
lib/write.ml*
lib/pretty.ml
lib/type.ml
96 changes: 43 additions & 53 deletions bench/bench.ml
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
open Core
open Core_bench

let data =
In_channel.read_all "bench.json"

let data = In_channel.read_all "bench.json"
let yojson_data = Yojson.Safe.from_string data

(* chosen by fair dice roll, guaranteed to be large *)
let large = 10_000

let large_int_assoc =
let ints = List.init large ~f:(fun n ->
(string_of_int n, `Int n))
in
let large_int_assoc =
let ints = List.init large ~f:(fun n -> (string_of_int n, `Int n)) in
`Assoc ints

let large_int_list =
let large_int_list =
let ints = List.init large ~f:(fun n -> `Int n) in
`List ints

let large_string_list =
let strings = List.init large ~f:(fun n ->
`String (string_of_int n))
in
let strings = List.init large ~f:(fun n -> `String (string_of_int n)) in
`List strings

let streamable_string =
Expand All @@ -33,53 +27,49 @@ let streamable_string =
Buffer.contents buf

let generic =
Bench.make_command [
Bench.Test.create ~name:"JSON reading" (fun () ->
ignore (Yojson.Safe.from_string data));
Bench.Test.create ~name:"JSON writing" (fun () ->
ignore (Yojson.Safe.to_string yojson_data));
Bench.Test.create ~name:"JSON writing assoc" (fun () ->
ignore (Yojson.Safe.to_string large_int_assoc));
Bench.Test.create ~name:"JSON writing int list" (fun () ->
ignore (Yojson.Safe.to_string large_int_list));
Bench.Test.create ~name:"JSON writing string list" (fun () ->
ignore (Yojson.Safe.to_string large_string_list));
Bench.Test.create ~name:"JSON writing int list to channel" (fun () ->
Out_channel.with_file "/dev/null" ~f:(fun oc ->
ignore (Yojson.Safe.to_channel oc large_int_list)));
Bench.Test.create ~name:"JSON writing string list to channel" (fun () ->
Out_channel.with_file "/dev/null" ~f:(fun oc ->
ignore (Yojson.Safe.to_channel oc large_string_list)));
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 seq roundtrip" (fun () ->
let stream = Yojson.Safe.seq_from_string ~buf streamable_string in
ignore (Yojson.Safe.seq_to_string ~buf stream)
)
end;
]
Bench.make_command
[
Bench.Test.create ~name:"JSON reading" (fun () ->
ignore (Yojson.Safe.from_string data));
Bench.Test.create ~name:"JSON writing" (fun () ->
ignore (Yojson.Safe.to_string yojson_data));
Bench.Test.create ~name:"JSON writing assoc" (fun () ->
ignore (Yojson.Safe.to_string large_int_assoc));
Bench.Test.create ~name:"JSON writing int list" (fun () ->
ignore (Yojson.Safe.to_string large_int_list));
Bench.Test.create ~name:"JSON writing string list" (fun () ->
ignore (Yojson.Safe.to_string large_string_list));
Bench.Test.create ~name:"JSON writing int list to channel" (fun () ->
Out_channel.with_file "/dev/null" ~f:(fun oc ->
ignore (Yojson.Safe.to_channel oc large_int_list)));
Bench.Test.create ~name:"JSON writing string list to channel" (fun () ->
Out_channel.with_file "/dev/null" ~f:(fun oc ->
ignore (Yojson.Safe.to_channel oc large_string_list)));
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)));
(let buf = Buffer.create 1000 in
Bench.Test.create ~name:"JSON seq roundtrip" (fun () ->
let stream = Yojson.Safe.seq_from_string ~buf streamable_string in
ignore (Yojson.Safe.seq_to_string ~buf stream)));
]

let buffer =
let buf = Buffer.create 4096 in
let data = large_int_assoc in
Bench.make_command [
Bench.Test.create ~name:"JSON writing with internal buffer" (fun () ->
Out_channel.with_file "/dev/null" ~f:(fun oc ->
ignore (Yojson.Safe.to_channel oc data)));
Bench.Test.create ~name:"JSON writing with provided buffer" (fun () ->
Out_channel.with_file "/dev/null" ~f:(fun oc ->
ignore (Yojson.Safe.to_channel ~buf oc data)));
]
Bench.make_command
[
Bench.Test.create ~name:"JSON writing with internal buffer" (fun () ->
Out_channel.with_file "/dev/null" ~f:(fun oc ->
ignore (Yojson.Safe.to_channel oc data)));
Bench.Test.create ~name:"JSON writing with provided buffer" (fun () ->
Out_channel.with_file "/dev/null" ~f:(fun oc ->
ignore (Yojson.Safe.to_channel ~buf oc data)));
]

let main () =
Command.group ~summary:"Benchmark" [
("generic", generic);
("buffer", buffer)
]
Command.group ~summary:"Benchmark"
[ ("generic", generic); ("buffer", buffer) ]
|> Command_unix.run

let () =
main ()
let () = main ()
Loading