Skip to content

Commit

Permalink
Remove json_io from benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonidas-from-XIV committed Jan 28, 2019
1 parent 9b4e8bd commit 0dc72f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
22 changes: 1 addition & 21 deletions bench/bench.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Printf

let data =
let l = ref [] in
try
Expand All @@ -10,7 +8,6 @@ let data =
with End_of_file -> String.concat "\n" (List.rev !l)

let yojson_data = Yojson.Safe.from_string data
let jsonwheel_data = Json_io.json_of_string data

let n = 10_000

Expand All @@ -24,30 +21,13 @@ let yojson_wr_loop () =
ignore (Yojson.Safe.to_string yojson_data)
done

let jsonwheel_rd_loop () =
for i = 1 to n do
ignore (Json_io.json_of_string data)
done

let jsonwheel_wr_loop () =
for i = 1 to n do
ignore (Json_io.string_of_json ~compact:true jsonwheel_data)
done

let time msg f =
let t1 = Unix.gettimeofday () in
f ();
let t2 = Unix.gettimeofday () in
printf "%s: %.3f\n%!" msg (t2 -. t1)
Printf.printf "%s: %.3f\n%!" msg (t2 -. t1)

let () =
time "rd yojson" yojson_rd_loop;
time "rd json-wheel" jsonwheel_rd_loop;
time "rd yojson" yojson_rd_loop;
time "rd json-wheel" jsonwheel_rd_loop;

time "wr yojson" yojson_wr_loop;
time "wr json-wheel" jsonwheel_wr_loop;
time "wr yojson" yojson_wr_loop;
time "wr json-wheel" jsonwheel_wr_loop

7 changes: 5 additions & 2 deletions bench/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
;; doesn't actually build b/c json_io doesn't exist
(executable
(name bench)
(flags (-safe-string))
(libraries yojson))
(libraries yojson unix))

(alias
(name bench)
(action (run ./bench.exe)))

0 comments on commit 0dc72f4

Please sign in to comment.