Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a benchmark showing the current performance of OpamVersionCompare #6078

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bench.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions tests/bench/bench.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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"
}
]
},
Expand All @@ -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
2 changes: 1 addition & 1 deletion tests/bench/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(executable
(name bench)
(libraries unix opam-core))
(libraries unix opam-core opam-format))
Loading