Skip to content

Commit

Permalink
Merge pull request #6078 from kit-ty-kate/bench-opamversioncompare
Browse files Browse the repository at this point in the history
Add a benchmark showing the current performance of OpamVersionCompare
  • Loading branch information
rjbou authored Jul 24, 2024
2 parents f28f033 + 4214da9 commit cb2181b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
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 @@ -119,6 +119,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))

0 comments on commit cb2181b

Please sign in to comment.