diff --git a/bench.Dockerfile b/bench.Dockerfile index d1341cd7533..d9774458193 100644 --- a/bench.Dockerfile +++ b/bench.Dockerfile @@ -14,4 +14,5 @@ RUN install ./opam /usr/local/bin/ USER opam RUN opam init --bare -n --disable-sandboxing /rep/opam-repository RUN opam switch create --fake default 4.14.0 +RUN opam list --all -s --all-versions > /home/opam/all-packages RUN find /rep/opam-repository -name opam -type f > /home/opam/all-opam-files diff --git a/master_changes.md b/master_changes.md index a33be817486..3f5f363c52a 100644 --- a/master_changes.md +++ b/master_changes.md @@ -118,6 +118,7 @@ users) ## Benchmarks * Make the benchmark setup process faster and the benchmark itself more stable [#6094 @kit-ty-kate] + * Add a benchmark showing the current performance of OpamVersionCompare [#6078 @kit-ty-kate] ## Reftests ### Tests diff --git a/tests/bench/bench.ml b/tests/bench/bench.ml index 7b2a3811532..b2106e2d891 100644 --- a/tests/bench/bench.ml +++ b/tests/bench/bench.ml @@ -63,6 +63,26 @@ let () = launch (fmt "%s install -y --fake core.v0.15.0" bin); time_cmd ~exit:0 (fmt "%s install --show --deps-only core.v0.15.0" bin) in + let time_OpamPackage_Version_compare_100 = + (* NOTE: https://github.com/ocaml/opam/pull/5518 *) + Gc.compact (); + let ic = Stdlib.open_in_bin "/home/opam/all-packages" in + let pkgs = + let rec loop pkgs = + match Stdlib.input_line ic with + | pkg -> loop (OpamPackage.version (OpamPackage.of_string pkg) :: pkgs) + | exception End_of_file -> pkgs + in + loop [] + in + let n = 100 in + let l = List.init n (fun _ -> + let before = Unix.gettimeofday () in + let _ = List.stable_sort OpamPackage.Version.compare pkgs in + Unix.gettimeofday () -. before) + in + List.fold_left (+.) 0.0 l /. float_of_int n + in let json = fmt {|{ "results": [ { @@ -92,6 +112,11 @@ let () = "name": "Deps-only install of an already installed package", "value": %f, "units": "secs" + }, + { + "name": "OpamPackage.Version.compare amortised over 100 runs", + "value": %f, + "units": "secs" } ] }, @@ -112,6 +137,7 @@ let () = time_install_cmd_w_invariant time_OpamSystem_read_100 time_deps_only_installed_pkg + time_OpamPackage_Version_compare_100 bin_size in print_endline json diff --git a/tests/bench/dune b/tests/bench/dune index bb4a1b46fe8..d7b23b43e8b 100644 --- a/tests/bench/dune +++ b/tests/bench/dune @@ -1,3 +1,3 @@ (executable (name bench) - (libraries unix opam-core)) + (libraries unix opam-core opam-format))