Skip to content

Commit

Permalink
Add a benchmark for OpamStd.String.split
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Dec 17, 2024
1 parent 48ca860 commit da36273
Show file tree
Hide file tree
Showing 3 changed files with 27 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
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ users)

## Benchmarks
* Add benchmarks for `opam show` [#6212 @kit-ty-kate]
* Add benchmarks for `OpamStd.String.split` [#6212 @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 @@ -117,6 +117,25 @@ let () =
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 @@ -186,6 +205,11 @@ let () =
"name": "opam show --raw pkgname.version",
"value": %f,
"units": "secs"
},
{
"name": "OpamStd.String.split amortised over 10 runs",
"value": %f,
"units": "secs"
}
]
},
Expand Down Expand Up @@ -214,6 +238,7 @@ let () =
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 da36273

Please sign in to comment.