Skip to content

Commit

Permalink
Merge branch 'bench-opamversioncompare' into speedup-OpamVersionCompare
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Jul 8, 2024
2 parents 7fe4c83 + c8dd3cc commit 71d09d0
Show file tree
Hide file tree
Showing 4 changed files with 28 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,3 +14,4 @@ RUN git -C opam-repository fetch origin $OPAMREPOSHA
RUN git -C opam-repository checkout $OPAMREPOSHA
RUN opam init -n --disable-sandboxing ./opam-repository
RUN find "$(pwd)/opam-repository" -name opam -type f > /home/opam/all-opam-files
RUN opam list --all -s --all-versions > /home/opam/all-packages
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ users)
## Test

## Benchmarks
* Add a benchmark showing the current performance of OpamVersionCompare [#6078 @kit-ty-kate]

## Reftests
### Tests
Expand Down
25 changes: 25 additions & 0 deletions tests/bench/bench.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ 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_10 =
(* NOTE: https://github.com/ocaml/opam/pull/5518 *)
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 before = Unix.gettimeofday () in
let n = 10 in
let l = List.init n (fun _ ->
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 @@ -84,6 +103,11 @@ let () =
"name": "Deps-only install of an already installed package",
"value": %f,
"units": "secs"
},
{
"name": "OpamPackage.Version.compare amortised over 10 runs",
"value": %f,
"units": "secs"
}
]
},
Expand All @@ -104,6 +128,7 @@ let () =
time_install_cmd_w_invariant
time_OpamSystem_read_10
time_deps_only_installed_pkg
time_OpamPackage_Version_compare_10
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 71d09d0

Please sign in to comment.