diff --git a/bench.Dockerfile b/bench.Dockerfile index e861bc41b6e..d202e0a6071 100644 --- a/bench.Dockerfile +++ b/bench.Dockerfile @@ -13,3 +13,4 @@ RUN git clone https://github.com/ocaml/opam-repository --depth 1 RUN git -C opam-repository fetch origin $OPAMREPOSHA RUN git -C opam-repository checkout $OPAMREPOSHA RUN opam init -n --disable-sandboxing ./opam-repository +RUN find "$(pwd)/opam-repository" -name opam -type f > /home/opam/all-opam-files diff --git a/master_changes.md b/master_changes.md index 26ecc54741d..33ed72bfccb 100644 --- a/master_changes.md +++ b/master_changes.md @@ -127,6 +127,9 @@ users) ## Test +## Benchmarks + * Benchmark OpamSystem.read [#5900 @kit-ty-kate] + ## Reftests ### Tests * Add init scripts tests [#5864 @rjbou] diff --git a/tests/bench/bench.ml b/tests/bench/bench.ml index f5d96bab536..83969583bda 100644 --- a/tests/bench/bench.ml +++ b/tests/bench/bench.ml @@ -33,6 +33,21 @@ let () = launch "opam switch set-invariant core -n --sw two"; time_cmd ~exit:0 (fmt "%s install magic-trace -y --fake --sw two" bin) in + let time_OpamSystem_read_10 = + let time_OpamSystem_read () = + let ic = Stdlib.open_in_bin "/home/opam/all-opam-files" in + let before = Unix.gettimeofday () in + let rec loop () = + match Stdlib.input_line ic with + | file -> ignore (OpamSystem.read file); loop () + | exception End_of_file -> Unix.gettimeofday () -. before + in + loop () + in + let n = 10 in + let l = List.init n (fun _ -> time_OpamSystem_read ()) in + List.fold_left (+.) 0.0 l /. float_of_int n + in let json = fmt {|{ "results": [ { @@ -52,6 +67,11 @@ let () = "name": "Fake install with invariant", "value": %f, "units": "secs" + }, + { + "name": "OpamSystem.read amortised over 10 runs", + "value": %f, + "units": "secs" } ] }, @@ -70,6 +90,7 @@ let () = time_misspelled_cmd time_install_cmd time_install_cmd_w_invariant + time_OpamSystem_read_10 bin_size in print_endline json diff --git a/tests/bench/dune b/tests/bench/dune index 92da1160e87..bb4a1b46fe8 100644 --- a/tests/bench/dune +++ b/tests/bench/dune @@ -1,3 +1,3 @@ (executable (name bench) - (libraries unix)) + (libraries unix opam-core))