Skip to content

Commit 5a1c97b

Browse files
authored
Merge pull request #5900 from kit-ty-kate/bench-opamsystem-read
Benchmark OpamSystem.read
2 parents 239945f + 80097a6 commit 5a1c97b

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

bench.Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ RUN git clone https://github.com/ocaml/opam-repository --depth 1
1313
RUN git -C opam-repository fetch origin $OPAMREPOSHA
1414
RUN git -C opam-repository checkout $OPAMREPOSHA
1515
RUN opam init -n --disable-sandboxing ./opam-repository
16+
RUN find "$(pwd)/opam-repository" -name opam -type f > /home/opam/all-opam-files

master_changes.md

+3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ users)
131131

132132
## Test
133133

134+
## Benchmarks
135+
* Benchmark OpamSystem.read [#5900 @kit-ty-kate]
136+
134137
## Reftests
135138
### Tests
136139
* Add init scripts tests [#5864 @rjbou]

tests/bench/bench.ml

+21
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ let () =
3333
launch "opam switch set-invariant core -n --sw two";
3434
time_cmd ~exit:0 (fmt "%s install magic-trace -y --fake --sw two" bin)
3535
in
36+
let time_OpamSystem_read_10 =
37+
let time_OpamSystem_read () =
38+
let ic = Stdlib.open_in_bin "/home/opam/all-opam-files" in
39+
let before = Unix.gettimeofday () in
40+
let rec loop () =
41+
match Stdlib.input_line ic with
42+
| file -> ignore (OpamSystem.read file); loop ()
43+
| exception End_of_file -> Unix.gettimeofday () -. before
44+
in
45+
loop ()
46+
in
47+
let n = 10 in
48+
let l = List.init n (fun _ -> time_OpamSystem_read ()) in
49+
List.fold_left (+.) 0.0 l /. float_of_int n
50+
in
3651
let json = fmt {|{
3752
"results": [
3853
{
@@ -52,6 +67,11 @@ let () =
5267
"name": "Fake install with invariant",
5368
"value": %f,
5469
"units": "secs"
70+
},
71+
{
72+
"name": "OpamSystem.read amortised over 10 runs",
73+
"value": %f,
74+
"units": "secs"
5575
}
5676
]
5777
},
@@ -70,6 +90,7 @@ let () =
7090
time_misspelled_cmd
7191
time_install_cmd
7292
time_install_cmd_w_invariant
93+
time_OpamSystem_read_10
7394
bin_size
7495
in
7596
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))
3+
(libraries unix opam-core))

0 commit comments

Comments
 (0)