Skip to content

Commit cb2181b

Browse files
authored
Merge pull request #6078 from kit-ty-kate/bench-opamversioncompare
Add a benchmark showing the current performance of OpamVersionCompare
2 parents f28f033 + 4214da9 commit cb2181b

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

bench.Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ RUN install ./opam /usr/local/bin/
1414
USER opam
1515
RUN opam init --bare -n --disable-sandboxing /rep/opam-repository
1616
RUN opam switch create --fake default 4.14.0
17+
RUN opam list --all -s --all-versions > /home/opam/all-packages
1718
RUN find /rep/opam-repository -name opam -type f > /home/opam/all-opam-files

master_changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ users)
119119

120120
## Benchmarks
121121
* Make the benchmark setup process faster and the benchmark itself more stable [#6094 @kit-ty-kate]
122+
* Add a benchmark showing the current performance of OpamVersionCompare [#6078 @kit-ty-kate]
122123

123124
## Reftests
124125
### Tests

tests/bench/bench.ml

+26
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ let () =
6363
launch (fmt "%s install -y --fake core.v0.15.0" bin);
6464
time_cmd ~exit:0 (fmt "%s install --show --deps-only core.v0.15.0" bin)
6565
in
66+
let time_OpamPackage_Version_compare_100 =
67+
(* NOTE: https://github.com/ocaml/opam/pull/5518 *)
68+
Gc.compact ();
69+
let ic = Stdlib.open_in_bin "/home/opam/all-packages" in
70+
let pkgs =
71+
let rec loop pkgs =
72+
match Stdlib.input_line ic with
73+
| pkg -> loop (OpamPackage.version (OpamPackage.of_string pkg) :: pkgs)
74+
| exception End_of_file -> pkgs
75+
in
76+
loop []
77+
in
78+
let n = 100 in
79+
let l = List.init n (fun _ ->
80+
let before = Unix.gettimeofday () in
81+
let _ = List.stable_sort OpamPackage.Version.compare pkgs in
82+
Unix.gettimeofday () -. before)
83+
in
84+
List.fold_left (+.) 0.0 l /. float_of_int n
85+
in
6686
let json = fmt {|{
6787
"results": [
6888
{
@@ -92,6 +112,11 @@ let () =
92112
"name": "Deps-only install of an already installed package",
93113
"value": %f,
94114
"units": "secs"
115+
},
116+
{
117+
"name": "OpamPackage.Version.compare amortised over 100 runs",
118+
"value": %f,
119+
"units": "secs"
95120
}
96121
]
97122
},
@@ -112,6 +137,7 @@ let () =
112137
time_install_cmd_w_invariant
113138
time_OpamSystem_read_100
114139
time_deps_only_installed_pkg
140+
time_OpamPackage_Version_compare_100
115141
bin_size
116142
in
117143
print_endline json

tests/bench/dune

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(executable
22
(name bench)
3-
(libraries unix opam-core))
3+
(libraries unix opam-core opam-format))

0 commit comments

Comments
 (0)