Skip to content

More benchmarks #2025

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

Merged
merged 4 commits into from
Jun 3, 2025
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 bench.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ RUN opam exec -- dune exec tools/ci_setup.exe ../janestreet . \
&& opam remove js_of_ocaml-compiler ojs \
&& opam clean

# Bin_prot packages
RUN opam pin add -n https://github.com/ocaml-wasm/bin_prot.git#wasm-v0.18 \
&& opam install ppx_bin_prot

# Copy sources
COPY --chown=opam:opam . ./

Expand Down
1 change: 1 addition & 0 deletions benchmarks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bench:
$(MAKE) -C benchmark-ocamlc bench
$(MAKE) -C benchmark-partial-render-table bench
$(MAKE) -C benchmark-camlboy bench
$(MAKE) -C benchmark-others bench

microbenchmarks:
@date -u +"%FT%TZ - Microbenchmarks: starting"
Expand Down
8 changes: 8 additions & 0 deletions benchmarks/benchmark-others/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SUBDIRS := $(wildcard */.)

bench: $(SUBDIRS)

$(SUBDIRS):
$(MAKE) -C $@

.PHONY: all $(SUBDIRS)
19 changes: 19 additions & 0 deletions benchmarks/benchmark-others/bigarrays/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: bench perform

export NAME=Others
export SUBNAME=bigarrays

SHELL=/bin/bash -o pipefail

bench:
@date -u +"%FT%TZ - $(NAME)/$(SUBNAME): starting"
ocamlc bench.ml -o bench
$(MAKE) perform COMPILER=js_of_ocaml SCRIPT=bench.js KIND=js
$(MAKE) perform COMPILER=wasm_of_ocaml SCRIPT=bench.wasm.js KIND=wasm
@date -u +"%FT%TZ - $(NAME)/$(SUBNAME): done"

perform:
$(COMPILER) --opt 2 --pretty bench -o $(SCRIPT)
/usr/bin/time -f '{"compiler": "$(COMPILER)", "time":"%E"}' node $(SCRIPT) 2>&1 | \
sh ../../utils/format_metrics.sh exec | \
sh ../../utils/aggregate.sh $(KIND)
36 changes: 36 additions & 0 deletions benchmarks/benchmark-others/bigarrays/bench.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
let pi = 4. *. atan 1.

let deltay = 40_000. /. 360. /. 3600. *. 1000.

let deltax = deltay *. cos (44. *. pi /. 180.)

let precompute tile_height tile_width tile =
let normals =
Bigarray.(Array3.create Int8_signed C_layout) (tile_height - 2) (tile_width - 2) 3
in
let heights =
Bigarray.(Array2.create Float32 C_layout) (tile_height - 2) (tile_width - 2)
in
for y = 1 to tile_height - 2 do
for x = 1 to tile_width - 2 do
let nx = (tile.{y, x - 1} -. tile.{y, x + 1}) *. deltay in
let ny = (tile.{y - 1, x} -. tile.{y + 1, x}) *. deltax in
let nz = 2. *. deltax *. deltay in
let n = 127. /. sqrt ((nx *. nx) +. (ny *. ny) +. (nz *. nz)) in
normals.{tile_height - 2 - y, x - 1, 0} <- truncate (nx *. n);
normals.{tile_height - 2 - y, x - 1, 1} <- truncate (ny *. n);
normals.{tile_height - 2 - y, x - 1, 2} <- truncate (nz *. n);
heights.{tile_height - 2 - y, x - 1} <- tile.{y, x}
done
done

let tile_height = 1024

let tile_width = 1024

let tile = Bigarray.(Array2.create Float32 C_layout) tile_height tile_width

let () =
for _ = 1 to 30 do
precompute tile_height tile_width tile
done
20 changes: 20 additions & 0 deletions benchmarks/benchmark-others/bin_prot/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: bench perform

export NAME=Others
export SUBNAME=bin_prot

SHELL=/bin/bash -o pipefail

bench:
@date -u +"%FT%TZ - $(NAME)/$(SUBNAME): starting"
dune build --profile release --root .
node _build/default/bench.bc.js 400000
$(MAKE) perform COMPILER=js_of_ocaml SCRIPT=_build/default/bench.bc.js KIND=js
$(MAKE) perform COMPILER=wasm_of_ocaml SCRIPT=_build/default/bench.bc.wasm.js KIND=wasm
@date -u +"%FT%TZ - $(NAME)/$(SUBNAME): done"

perform:
/usr/bin/time -f '{"compiler": "$(COMPILER)", "time":"%E"}' node $(SCRIPT) 2>&1 1> /dev/null | \
tee /dev/stderr | \
sh ../../utils/format_metrics.sh exec | \
sh ../../utils/aggregate.sh $(KIND)
83 changes: 83 additions & 0 deletions benchmarks/benchmark-others/bin_prot/bench.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
open Bin_prot.Std

type element =
{ a : string
; b : string
; c : string
; d : bool
; e : bool
; f : bool
; g : string option
; h : bool
; i : bool
; j : bool
; k : bool
; l : bool
; m : bool
; n : bool
; o : string option
; p : bool
; q : bool
; r : int
; s : int
; t : int
; u : int
; v : string list (* these are small - 1-5 *)
}
[@@deriving bin_io]

let s = "abcdefabcdefabcdef"

let v = [ s; s; s; s ]

let x =
{ a = s
; b = s
; c = s
; d = true
; e = true
; f = true
; g = Some s
; h = true
; i = true
; j = true
; k = true
; l = true
; m = true
; n = true
; o = Some s
; p = true
; q = true
; r = 65537
; s = 65537
; t = 65537
; u = 65537
; v
}

type t = element list [@@deriving bin_io]

let rec f acc n = if n = 0 then acc else f (x :: acc) (n - 1)

let () =
if Array.length Sys.argv > 1
then (
let count = int_of_string Sys.argv.(1) in
let l = f [] count in
let len = [%bin_size: t] l in
let b = Bin_prot.Common.create_buf len in
ignore ([%bin_write: t] b ~pos:0 l : int);
let s = Bytes.create len in
Bin_prot.Common.blit_buf_string ~src_pos:0 b ~dst_pos:0 s ~len;
Out_channel.with_open_bin "data" @@ fun ch -> Out_channel.output_bytes ch s)
else
let s = In_channel.with_open_bin "data" @@ In_channel.input_all in
let len = String.length s in
let b = Bin_prot.Common.create_buf len in
Bin_prot.Common.blit_string_buf ~src_pos:0 s ~dst_pos:0 b ~len;
let t = Unix.gettimeofday () in
for _ = 0 to 4 do
ignore ([%bin_read: t] b ~pos_ref:(ref 0) : t)
done;
let t' = Unix.gettimeofday () in
Format.printf "%.2f@." (t' -. t)
10 changes: 10 additions & 0 deletions benchmarks/benchmark-others/bin_prot/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(executables
(names bench)
(modes js wasm)
(js_of_ocaml
(flags --opt 2))
(wasm_of_ocaml
(flags --opt 2))
(preprocess
(pps ppx_bin_prot))
(libraries unix))
1 change: 1 addition & 0 deletions benchmarks/benchmark-others/bin_prot/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.19)
3 changes: 3 additions & 0 deletions benchmarks/benchmark-others/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; Ignore subdirectories

(dirs)
Loading
Loading