Skip to content

Commit

Permalink
Merge pull request #6212 from kit-ty-kate/bench-opam-show
Browse files Browse the repository at this point in the history
Add benchmarks for opam show and String.split
  • Loading branch information
kit-ty-kate authored Dec 17, 2024
2 parents 8f48372 + da36273 commit cdb49a5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions bench.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ 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
RUN cat /home/opam/all-opam-files | xargs -d '\n' cat > /home/opam/all-opam-content
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ users)
## Test

## Benchmarks
* Add benchmarks for `opam show` [#6212 @kit-ty-kate]
* Add benchmarks for `OpamStd.String.split` [#6212 @kit-ty-kate]

## Reftests
### Tests
Expand Down
67 changes: 67 additions & 0 deletions tests/bench/bench.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,43 @@ let () =
launch (fmt "%s switch create six --empty" bin);
time_cmd ~exit:0 (fmt "%s list --installed --short --safe --color=never ocp-indent ocp-index merlin" bin)
in
launch (fmt "%s switch create seven --empty" bin);
launch (fmt "%s install -y --fake dune" bin);
let time_show_installed =
Gc.compact ();
time_cmd ~exit:0 (fmt "%s show dune" bin)
in
let time_show_with_depexts =
Gc.compact ();
time_cmd ~exit:0 (fmt "%s show conf-llvm" bin)
in
let time_show_raw =
Gc.compact ();
time_cmd ~exit:0 (fmt "%s show --raw conf-llvm" bin)
in
let time_show_precise =
Gc.compact ();
time_cmd ~exit:0 (fmt "%s show --raw conf-llvm.14.0.6" bin)
in
let time_OpamStd_String_split_10 =
Gc.compact ();
let lines =
let ic = Stdlib.open_in_bin "/home/opam/all-opam-content" in
let rec loop files =
match Stdlib.input_line ic with
| file -> loop (file :: files)
| exception End_of_file -> files
in
loop []
in
let n = 10 in
let l = List.init n (fun _ ->
let before = Unix.gettimeofday () in
List.iter (fun line -> ignore (OpamStd.String.split line ' ')) lines;
Unix.gettimeofday () -. before)
in
List.fold_left (+.) 0.0 l /. float_of_int n
in
let json = fmt {|{
"results": [
{
Expand Down Expand Up @@ -148,6 +185,31 @@ let () =
"name": "opam list --installed on non-installed packages",
"value": %f,
"units": "secs"
},
{
"name": "opam show of an installed package",
"value": %f,
"units": "secs"
},
{
"name": "opam show with depexts",
"value": %f,
"units": "secs"
},
{
"name": "opam show --raw pkgname",
"value": %f,
"units": "secs"
},
{
"name": "opam show --raw pkgname.version",
"value": %f,
"units": "secs"
},
{
"name": "OpamStd.String.split amortised over 10 runs",
"value": %f,
"units": "secs"
}
]
},
Expand All @@ -172,6 +234,11 @@ let () =
time_install_check_installed
time_install_check_not_installed
time_list_installed_noninstalled_packages
time_show_installed
time_show_with_depexts
time_show_raw
time_show_precise
time_OpamStd_String_split_10
bin_size
in
print_endline json

0 comments on commit cdb49a5

Please sign in to comment.