Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup benchmarking using current-bench #5525

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ uninstall: opam.install
.PHONY: test
test: tests

.PHONY: bench
bench:
@$(DUNE) exec --display=quiet $(DUNE_PROFILE_ARG) --root . $(DUNE_ARGS) -- ./tests/bench/bench.exe

.PHONY: tests
tests: $(DUNE_DEP) src/client/no-git-version
@$(DUNE) runtest $(DUNE_PROFILE_ARG) --root . $(DUNE_ARGS) src/ tests/ --no-buffer; \
Expand Down
11 changes: 11 additions & 0 deletions bench.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM debian
RUN apt-get update -qq && apt-get install -qq -yy make curl gcc g++ patch bzip2 git unzip
RUN adduser --disabled-password --gecos '' --shell /bin/bash opam
USER opam
COPY --chown=opam:opam . /src
WORKDIR /src
RUN make cold
USER root
RUN install ./opam /usr/local/bin/
USER opam
RUN opam init -n --disable-sandboxing git+https://github.com/ocaml/opam-repository#26770281fa1ea8b13aab979c1dfbd326e9ab512c
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ users)
## Test
* Update crowbar with compare functions [#4918 @rjbou]
* No more mute test debug output (level < 0) if `--readonly` is given with `--debug-level` [#5476 @rjbou]
* Setup benchmarking using current-bench [#5525 @kit-ty-kate]

## Reftests
### Tests
Expand Down
45 changes: 45 additions & 0 deletions tests/bench/bench.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
let fmt = Printf.sprintf

let time_cmd ~exit cmd =
let cmd = cmd ^ " 2> /dev/null > /dev/null" in
let before = Unix.gettimeofday () in
let code = Sys.command cmd in
let timer = Unix.gettimeofday () -. before in
if Int.equal code exit then
timer
else
failwith (fmt "Command %S exited with error code %d" cmd code)

let () =
let bin = "./opam" in
let bin_size = (Unix.stat bin).st_size in
let time_misspelled_cmd =
(* NOTE: https://github.com/ocaml/opam/issues/5479 *)
time_cmd ~exit:2 (fmt "%s sitch" bin)
in
let json = fmt {|{
"results": [
{
"name": "Timings",
"metrics": [
{
"name": "Misspelled command",
"value": %f,
"units": "secs"
}
]
},
{
"name": "Misc",
"metrics": [
{
"name": "Size of opam.exe",
"value": %d,
"units": "bytes"
}
]
}
]
}|} time_misspelled_cmd bin_size
in
print_endline json
3 changes: 3 additions & 0 deletions tests/bench/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name bench)
(libraries unix))