From da362732fcafc09cf12b34e92a657b6c574699f9 Mon Sep 17 00:00:00 2001 From: Kate Date: Wed, 4 Dec 2024 20:58:07 +0000 Subject: [PATCH] Add a benchmark for OpamStd.String.split --- bench.Dockerfile | 1 + master_changes.md | 1 + tests/bench/bench.ml | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+) 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 fdaf3330240..ea025fbf940 100644 --- a/master_changes.md +++ b/master_changes.md @@ -139,6 +139,7 @@ users) ## 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 0d03bb7d340..d0bf088b698 100644 --- a/tests/bench/bench.ml +++ b/tests/bench/bench.ml @@ -117,6 +117,25 @@ let () = 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": [ { @@ -186,6 +205,11 @@ let () = "name": "opam show --raw pkgname.version", "value": %f, "units": "secs" + }, + { + "name": "OpamStd.String.split amortised over 10 runs", + "value": %f, + "units": "secs" } ] }, @@ -214,6 +238,7 @@ let () = time_show_with_depexts time_show_raw time_show_precise + time_OpamStd_String_split_10 bin_size in print_endline json