Skip to content

Commit efbb28a

Browse files
committed
Benchmark: bin_prot
1 parent 91826c5 commit efbb28a

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.PHONY: bench perform
2+
3+
export NAME=Others/bin_prot
4+
5+
SHELL=/bin/bash -o pipefail
6+
7+
bench:
8+
@date -u +"%FT%TZ - $(NAME): starting"
9+
opam pin add -n https://github.com/ocaml-wasm/bin_prot.git#wasm-v0.18
10+
opam install ppx_bin_prot
11+
dune build --profile release --root .
12+
node _build/default/bench.bc.js 400000
13+
$(MAKE) perform COMPILER=js_of_ocaml SCRIPT=_build/default/bench.bc.js KIND=js
14+
$(MAKE) perform COMPILER=wasm_of_ocaml SCRIPT=_build/default/bench.bc.wasm.js KIND=wasm
15+
@date -u +"%FT%TZ - $(NAME): done"
16+
17+
perform:
18+
/usr/bin/time -f '{"compiler": "$(COMPILER)", "time":"%E"}' node $(SCRIPT) 2>&1 1> /dev/null | \
19+
tee /dev/stderr | \
20+
sh ../../utils/format_metrics.sh exec | \
21+
sh ../../utils/aggregate.sh $(KIND)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
open Bin_prot.Std
2+
3+
type element =
4+
{ a : string
5+
; b : string
6+
; c : string
7+
; d : bool
8+
; e : bool
9+
; f : bool
10+
; g : string option
11+
; h : bool
12+
; i : bool
13+
; j : bool
14+
; k : bool
15+
; l : bool
16+
; m : bool
17+
; n : bool
18+
; o : string option
19+
; p : bool
20+
; q : bool
21+
; r : int
22+
; s : int
23+
; t : int
24+
; u : int
25+
; v : string list (* these are small - 1-5 *)
26+
}
27+
[@@deriving bin_io]
28+
29+
let s = "abcdefabcdefabcdef"
30+
31+
let v = [ s; s; s; s ]
32+
33+
let x =
34+
{ a = s
35+
; b = s
36+
; c = s
37+
; d = true
38+
; e = true
39+
; f = true
40+
; g = Some s
41+
; h = true
42+
; i = true
43+
; j = true
44+
; k = true
45+
; l = true
46+
; m = true
47+
; n = true
48+
; o = Some s
49+
; p = true
50+
; q = true
51+
; r = 65537
52+
; s = 65537
53+
; t = 65537
54+
; u = 65537
55+
; v
56+
}
57+
58+
type t = element list [@@deriving bin_io]
59+
60+
let rec f acc n = if n = 0 then acc else f (x :: acc) (n - 1)
61+
62+
let () =
63+
if Array.length Sys.argv > 1
64+
then (
65+
let count = int_of_string Sys.argv.(1) in
66+
let l = f [] count in
67+
let len = [%bin_size: t] l in
68+
let b = Bin_prot.Common.create_buf len in
69+
ignore ([%bin_write: t] b ~pos:0 l : int);
70+
let s = Bytes.create len in
71+
Bin_prot.Common.blit_buf_string ~src_pos:0 b ~dst_pos:0 s ~len;
72+
Out_channel.with_open_bin "data" @@ fun ch -> Out_channel.output_bytes ch s)
73+
else
74+
let s = In_channel.with_open_bin "data" @@ In_channel.input_all in
75+
let len = String.length s in
76+
let b = Bin_prot.Common.create_buf len in
77+
Bin_prot.Common.blit_string_buf ~src_pos:0 s ~dst_pos:0 b ~len;
78+
let t = Unix.gettimeofday () in
79+
for _ = 0 to 4 do
80+
ignore ([%bin_read: t] b ~pos_ref:(ref 0) : t)
81+
done;
82+
let t' = Unix.gettimeofday () in
83+
Format.printf "%.2f@." (t' -. t)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(executables
2+
(names bench)
3+
(modes js wasm)
4+
(js_of_ocaml
5+
(flags --opt 2))
6+
(wasm_of_ocaml
7+
(flags --opt 2))
8+
(preprocess
9+
(pps ppx_bin_prot))
10+
(libraries unix))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 3.19)

0 commit comments

Comments
 (0)