Skip to content

Commit

Permalink
Setup benchmarking using current-bench
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Apr 25, 2023
1 parent fd29dc4 commit 20147b9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
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) -- ./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
45 changes: 45 additions & 0 deletions 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 bench/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name bench)
(libraries unix))
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

0 comments on commit 20147b9

Please sign in to comment.