diff --git a/bench.Dockerfile b/bench.Dockerfile index d9774458193..0631f4c8469 100644 --- a/bench.Dockerfile +++ b/bench.Dockerfile @@ -16,3 +16,4 @@ 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 +RUN cat /home/opam/all-opam-files | xargs -d '\n' cat > /home/opam/all-opam-content diff --git a/master_changes.md b/master_changes.md index f1ce6fe007c..f5a6340d329 100644 --- a/master_changes.md +++ b/master_changes.md @@ -144,6 +144,8 @@ users) ## Test ## Benchmarks + * Add benchmarks for `opam show` [#6212 @kit-ty-kate] + * Add benchmarks for `OpamStd.String.split` [#6212 @kit-ty-kate] ## Reftests ### Tests diff --git a/tests/bench/bench.ml b/tests/bench/bench.ml index d55c07edcee..d0bf088b698 100644 --- a/tests/bench/bench.ml +++ b/tests/bench/bench.ml @@ -99,6 +99,43 @@ let () = launch (fmt "%s switch create six --empty" bin); time_cmd ~exit:0 (fmt "%s list --installed --short --safe --color=never ocp-indent ocp-index merlin" bin) in + launch (fmt "%s switch create seven --empty" bin); + launch (fmt "%s install -y --fake dune" bin); + let time_show_installed = + Gc.compact (); + time_cmd ~exit:0 (fmt "%s show dune" bin) + in + let time_show_with_depexts = + Gc.compact (); + time_cmd ~exit:0 (fmt "%s show conf-llvm" bin) + in + let time_show_raw = + Gc.compact (); + time_cmd ~exit:0 (fmt "%s show --raw conf-llvm" bin) + in + let time_show_precise = + Gc.compact (); + time_cmd ~exit:0 (fmt "%s show --raw conf-llvm.14.0.6" bin) + in + let time_OpamStd_String_split_10 = + Gc.compact (); + let lines = + let ic = Stdlib.open_in_bin "/home/opam/all-opam-content" in + let rec loop files = + match Stdlib.input_line ic with + | file -> loop (file :: files) + | exception End_of_file -> files + in + loop [] + in + let n = 10 in + let l = List.init n (fun _ -> + let before = Unix.gettimeofday () in + List.iter (fun line -> ignore (OpamStd.String.split line ' ')) lines; + Unix.gettimeofday () -. before) + in + List.fold_left (+.) 0.0 l /. float_of_int n + in let json = fmt {|{ "results": [ { @@ -148,6 +185,31 @@ let () = "name": "opam list --installed on non-installed packages", "value": %f, "units": "secs" + }, + { + "name": "opam show of an installed package", + "value": %f, + "units": "secs" + }, + { + "name": "opam show with depexts", + "value": %f, + "units": "secs" + }, + { + "name": "opam show --raw pkgname", + "value": %f, + "units": "secs" + }, + { + "name": "opam show --raw pkgname.version", + "value": %f, + "units": "secs" + }, + { + "name": "OpamStd.String.split amortised over 10 runs", + "value": %f, + "units": "secs" } ] }, @@ -172,6 +234,11 @@ let () = time_install_check_installed time_install_check_not_installed time_list_installed_noninstalled_packages + time_show_installed + time_show_with_depexts + time_show_raw + time_show_precise + time_OpamStd_String_split_10 bin_size in print_endline json