Skip to content

Commit

Permalink
Merge pull request #5900 from kit-ty-kate/bench-opamsystem-read
Browse files Browse the repository at this point in the history
Benchmark OpamSystem.read
  • Loading branch information
kit-ty-kate authored Apr 2, 2024
2 parents 239945f + 80097a6 commit 5a1c97b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions bench.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ RUN git clone https://github.com/ocaml/opam-repository --depth 1
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
3 changes: 3 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ users)

## Test

## Benchmarks
* Benchmark OpamSystem.read [#5900 @kit-ty-kate]

## Reftests
### Tests
* Add init scripts tests [#5864 @rjbou]
Expand Down
21 changes: 21 additions & 0 deletions tests/bench/bench.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ let () =
launch "opam switch set-invariant core -n --sw two";
time_cmd ~exit:0 (fmt "%s install magic-trace -y --fake --sw two" bin)
in
let time_OpamSystem_read_10 =
let time_OpamSystem_read () =
let ic = Stdlib.open_in_bin "/home/opam/all-opam-files" in
let before = Unix.gettimeofday () in
let rec loop () =
match Stdlib.input_line ic with
| file -> ignore (OpamSystem.read file); loop ()
| exception End_of_file -> Unix.gettimeofday () -. before
in
loop ()
in
let n = 10 in
let l = List.init n (fun _ -> time_OpamSystem_read ()) in
List.fold_left (+.) 0.0 l /. float_of_int n
in
let json = fmt {|{
"results": [
{
Expand All @@ -52,6 +67,11 @@ let () =
"name": "Fake install with invariant",
"value": %f,
"units": "secs"
},
{
"name": "OpamSystem.read amortised over 10 runs",
"value": %f,
"units": "secs"
}
]
},
Expand All @@ -70,6 +90,7 @@ let () =
time_misspelled_cmd
time_install_cmd
time_install_cmd_w_invariant
time_OpamSystem_read_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))
(libraries unix opam-core))

0 comments on commit 5a1c97b

Please sign in to comment.