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

Add wasm_of_ocaml benchmarks with current-bench output #1842

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ _build
benchmarks/*.svg
benchmarks/*.pdf
benchmarks/__run
benchmarks/__run_wasm
benchmarks/build
benchmarks/results
benchmarks/config
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Runtime: remove polyfill for Map to simplify MlObjectTable implementation (#1846)
* Runtime: refactor caml_xmlhttprequest_create implementation (#1846)
* Runtime: update constant imports to use `node:fs` module (#1850)
* Misc: add a benchmarking suite for wasm_of_ocaml targeting [current-bench](https://github.com/ocurrent/current-bench)

## Bug fixes
* Runtime: fix path normalization (#1848)
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ installdoc:
git worktree add _wikidoc origin/wikidoc
rsync -av doc-dev/ _wikidoc/doc/dev/

.PHONY: all tests tests-wasm test runtest runtests doc clean installdoc
bench:
$(MAKE) -C benchmarks bench

.PHONY: all tests tests-wasm test runtest runtests doc clean installdoc bench
26 changes: 26 additions & 0 deletions bench.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ocaml/opam:debian-ocaml-5.3
WORKDIR /bench-dir
RUN sudo apt-get update && \
sudo apt-get install -qq -yy --no-install-recommends pkg-config libgmp-dev \
wget
RUN sudo ln -sf /usr/bin/opam-2.3 /usr/bin/opam
RUN opam remote add origin https://github.com/ocaml/opam-repository.git && \
opam update
RUN wget https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-x64.tar.xz && \
tar xJvf node-v22.14.0-linux-x64.tar.xz && \
sudo cp node-v22.14.0-linux-x64/bin/node /usr/bin/node
COPY --chown=opam:opam ./*.opam ./VERSION ./
RUN opam exec -- git init && \
opam exec -- git add . && \
opam exec -- git commit -m dummy && \
opam exec -- git tag -a $(cat VERSION)-dev -m dummy
RUN opam pin -yn --with-version=dev .
RUN opam install -y --depext-only wasm_of_ocaml-compiler && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this line unnecessary?

opam install -y --deps-only js_of_ocaml-compiler && \
opam install -y binaryen-bin
COPY --chown=opam:opam . ./
RUN opam exec -- git add . && \
opam exec -- git commit -m dummy && \
opam exec -- git tag -a $(cat VERSION)-dev-2 -m dummy
RUN opam install -y wasm_of_ocaml-compiler
WORKDIR ./benchmarks
12 changes: 12 additions & 0 deletions benchmarks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ GRAPHSEFF = time-effects.pdf size-effects.pdf size-bzip2-effects.pdf
# For full benchs:
all: _perf graphsnopr graphspr graphseff _noperf

# This target is the one run by `current-bench`,
# see https://github.com/ocurrent/current-bench
.PHONY: bench
bench: __run_wasm
$(REPORT) -format current-bench -config report-wasm-cb.config \
-ylabel "Wasm_of_ocaml"


graphsnopr: _noprecomp $(GRAPHSNOPR)

graphspr: __precomp $(GRAPHSPR)
Expand Down Expand Up @@ -51,6 +59,10 @@ __run_effects:
$(RUN) -fast -nobyteopt -effects
touch __run_effects

__run_wasm:
$(RUN) -nobyteopt -wasm -nojs -verbose
touch __run_wasm

fastrun:
make _noprecomp
echo "======================== WARNING: fast benchs!"
Expand Down
61 changes: 52 additions & 9 deletions benchmarks/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,46 @@ let code = "build"

let hostname = Unix.gethostname ()

let times = Filename.concat "results/times" hostname
module Measure = struct
type t =
{ name : string
; units : string
; description : string option
; trend : string option
; path : string
; color : string option
}
end

let sizes = "results/sizes"
let times =
Measure.
{ name = "execution-time"
; units = "s"
; description = Some "Execution time"
; trend = Some "lower-is-better"
; path = Filename.concat "results/times" hostname
; color = None
}

let compiletimes = Filename.concat "results/compiletimes" hostname
let sizes =
Measure.
{ name = "code-size"
; units = "B"
; description = Some "Code size"
; trend = Some "lower-is-better"
; path = "results/sizes"
; color = None
}

let compiletimes =
Measure.
{ name = "compile-time"
; units = "s"
; description = Some "Compile time"
; trend = Some "lower-is-better"
; path = Filename.concat "results/compiletimes" hostname
; color = None
}

module Spec : sig
type t
Expand All @@ -139,6 +174,8 @@ module Spec : sig

val js : t

val wasm : t

val byte : t

val opt : t
Expand All @@ -164,6 +201,8 @@ module Spec : sig
val js_of_ocaml_call : t

val js_of_ocaml_effects : t

val wasm_of_ocaml : t
end = struct
type t =
{ dir : string
Expand Down Expand Up @@ -202,6 +241,8 @@ end = struct

let js = create "js" ".js"

let wasm = create "wasm" ".js"

let byte = create "byte" ""

let opt = create "opt" ""
Expand All @@ -227,6 +268,8 @@ end = struct
let js_of_ocaml_call = create "nooptcall" ".js"

let js_of_ocaml_effects = create "effects" ".js"

let wasm_of_ocaml = create "wasm_of_ocaml" ".js"
end

let rec mkdir d =
Expand All @@ -246,11 +289,11 @@ let need_update src dst =

let measures_need_update code meas spec nm =
let p = Spec.file ~root:code spec nm in
let m = Spec.file ~root:meas (Spec.no_ext spec) nm in
let m = Spec.file ~root:meas.Measure.path (Spec.no_ext spec) nm in
need_update p m

let read_measures meas spec nm =
let m = Spec.file ~root:meas (Spec.no_ext spec) nm in
let read_measures path spec nm =
let m = Spec.file ~root:path (Spec.no_ext spec) nm in
let l = ref [] in
if Sys.file_exists m
then (
Expand All @@ -265,9 +308,9 @@ let read_measures meas spec nm =
else []

let write_measures meas spec nm l =
let m = Spec.file ~root:meas (Spec.no_ext spec) nm in
let tmp = Spec.file ~root:meas (Spec.no_ext spec) "_tmp_" in
mkdir (Spec.dir ~root:meas spec);
let m = Spec.file ~root:meas.Measure.path (Spec.no_ext spec) nm in
let tmp = Spec.file ~root:meas.Measure.path (Spec.no_ext spec) "_tmp_" in
mkdir (Spec.dir ~root:meas.Measure.path spec);
let ch = open_out tmp in
List.iter ~f:(fun t -> Printf.fprintf ch "%f\n" t) (List.rev l);
close_out ch;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executables
(names report run stripdebug)
(libraries unix compiler-libs.bytecomp))
(libraries unix compiler-libs.bytecomp yojson))

(alias
(name default)
Expand Down
1 change: 1 addition & 0 deletions benchmarks/report-wasm-cb.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
histogram times node wasm_of_ocaml #ffffff node
Loading
Loading