diff --git a/CHANGES.md b/CHANGES.md index afb121aeed..d9bdadb0c6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,8 @@ - **irmin-bench** (_new_): - Created a new package to contain benchmarks for Irmin and its various backends. (#1142, @CraigFe) + - Added ability to get json output and a make target to run layers benchmark. + (#1146, @gs0510) - **irmin** - Added `Tree.{Contents,Node}` modules exposing operations over lazy tree diff --git a/Makefile b/Makefile index 26d4628db2..778df4f7de 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all clean test fuzz bench-mem bench-pack bench doc examples +.PHONY: all clean test fuzz bench-mem bench-pack bench-layers bench doc examples all: dune build @@ -12,7 +12,10 @@ bench-mem: bench-pack: dune exec ./test/irmin-pack/bench.exe -bench: bench-mem bench-pack +bench-layers: + dune exec -- ./bench/irmin-pack/layers.exe -n 2005 -b 2 -j + +bench: bench-mem bench-pack bench-layers fuzz: dune build @fuzz --no-buffer diff --git a/bench/irmin-pack/dune b/bench/irmin-pack/dune index 8aa03f2cd7..3711fd75ac 100644 --- a/bench/irmin-pack/dune +++ b/bench/irmin-pack/dune @@ -1,6 +1,9 @@ (executables (names main layers) - (libraries irmin-pack irmin-test.bench irmin-layers lwt unix cmdliner logs)) + (preprocess + (pps ppx_deriving_yojson)) + (libraries irmin-pack irmin-test.bench irmin-layers lwt unix cmdliner logs + yojson ppx_deriving_yojson)) ;; Require the above executables to compile during tests diff --git a/bench/irmin-pack/layers.ml b/bench/irmin-pack/layers.ml index 40d75e5690..f7d99da0fd 100644 --- a/bench/irmin-pack/layers.ml +++ b/bench/irmin-pack/layers.ml @@ -229,7 +229,7 @@ let first_5_cycles config repo = print_commit_stats config c 0 0.0; let rec aux i c = add_min c; - if i >= 4 then Lwt.return c + if i > 4 then Lwt.return c else write_cycle config repo c >>= fun c -> aux (i + 1) c in aux 0 c @@ -267,7 +267,28 @@ let run config = Fmt.epr "After freeze thread finished : "; FSHelper.print_size config.root) -let main () ncommits ncycles depth clear no_freeze show_stats = +type result = { + total_time : float; + time_per_commit : float; + commits_per_sec : float; +} +[@@deriving yojson] + +let get_json_str total_time time_per_commit commits_per_sec = + let res = { total_time; time_per_commit; commits_per_sec } in + let obj = + `Assoc + [ + ( "results", + `Assoc + [ + ("name", `String "benchmarks"); ("metrics", result_to_yojson res); + ] ); + ] + in + Yojson.Safe.to_string obj + +let main () ncommits ncycles depth clear no_freeze show_stats json = let config = { ncommits; @@ -281,13 +302,15 @@ let main () ncommits ncycles depth clear no_freeze show_stats = in init config; let d, _ = Lwt_main.run (with_timer (fun () -> run config)) in - let all_commits = ncommits * ncycles in + let all_commits = ncommits * (ncycles + 5) in let rate = d /. float all_commits in let freq = 1. /. rate in - Logs.app (fun l -> - l - "%d commits completed in %.2fs.\n\ - [%.3fs per commit, %.0f commits per second]" all_commits d rate freq) + if json then Logs.app (fun l -> l "%s" (get_json_str d rate freq)) + else + Logs.app (fun l -> + l + "%d commits completed in %.2fs.\n\ + [%.3fs per commit, %.0f commits per second]" all_commits d rate freq) open Cmdliner @@ -296,7 +319,13 @@ let ncommits = Arg.(value @@ opt int 4096 doc) let ncycles = - let doc = Arg.info ~doc:"Number of cycles." [ "b"; "ncycles" ] in + let doc = + Arg.info + ~doc: + "Number of cycles. This will be in addition to the 5 cycles that run \ + to emulate freeze." + [ "b"; "ncycles" ] + in Arg.(value @@ opt int 10 doc) let depth = @@ -317,6 +346,10 @@ let stats = let doc = Arg.info ~doc:"Show performance stats." [ "s"; "stats" ] in Arg.(value @@ flag doc) +let json = + let doc = Arg.info ~doc:"Json output on command line." [ "j"; "json" ] in + Arg.(value @@ flag doc) + let setup_log style_renderer level = Fmt_tty.setup_std_outputs ?style_renderer (); Logs.set_level level; @@ -335,7 +368,8 @@ let main_term = $ depth $ clear $ no_freeze - $ stats) + $ stats + $ json) let () = let info = Term.info "Benchmarks for layered store" in diff --git a/irmin-bench.opam b/irmin-bench.opam index 25a0f467cf..c702aa4216 100644 --- a/irmin-bench.opam +++ b/irmin-bench.opam @@ -19,6 +19,8 @@ depends: [ "cmdliner" "logs" "lwt" + "ppx_deriving_yojson" + "yojson" ] synopsis: "Irmin benchmarking suite"