File tree Expand file tree Collapse file tree 8 files changed +175
-0
lines changed
Expand file tree Collapse file tree 8 files changed +175
-0
lines changed Original file line number Diff line number Diff line change 1717 @date -u +" %FT%TZ - Installing dependencies"
1818 opam pin -yn --with-version=dev ..
1919 opam install -y wasm_of_ocaml-compiler js_of_ocaml-ppx gen_js_api brr
20+ $(MAKE ) -C benchmark-others bench
2021 $(MAKE ) microbenchmarks
2122 $(MAKE ) -C benchmark-fiat-crypto bench
2223 $(MAKE ) -C benchmark-ocamlc bench
Original file line number Diff line number Diff line change 1+ SUBDIRS := $(wildcard * /.)
2+
3+ bench : $(SUBDIRS )
4+
5+ $(SUBDIRS ) :
6+ $(MAKE ) -C $@
7+
8+ .PHONY : all $(SUBDIRS )
Original file line number Diff line number Diff line change 1+ .PHONY : bench perform
2+
3+ export NAME =Others/bigarrays
4+
5+ SHELL =/bin/bash -o pipefail
6+
7+ bench :
8+ @date -u +" %FT%TZ - $( NAME) : starting"
9+ ocamlc bench.ml -o bench
10+ $(MAKE ) perform COMPILER=js_of_ocaml SCRIPT=bench.js KIND=js
11+ $(MAKE ) perform COMPILER=wasm_of_ocaml SCRIPT=bench.wasm.js KIND=wasm
12+ @date -u +" %FT%TZ - $( NAME) : done"
13+
14+ perform :
15+ $(COMPILER ) --opt 2 --pretty bench -o $(SCRIPT )
16+ /usr/bin/time -f ' {"compiler": "$(COMPILER)", "time":"%E"}' node $(SCRIPT ) 2>&1 | \
17+ sh ../../utils/format_metrics.sh exec | \
18+ sh ../../utils/aggregate.sh $(KIND )
Original file line number Diff line number Diff line change 1+ let pi = 4. *. atan 1.
2+
3+ let deltay = 40_000. /. 360. /. 3600. *. 1000.
4+
5+ let deltax = deltay *. cos (44. *. pi /. 180. )
6+
7+ let precompute tile_height tile_width tile =
8+ let normals =
9+ Bigarray. (Array3. create Int8_signed C_layout ) (tile_height - 2 ) (tile_width - 2 ) 3
10+ in
11+ let heights =
12+ Bigarray. (Array2. create Float32 C_layout ) (tile_height - 2 ) (tile_width - 2 )
13+ in
14+ for y = 1 to tile_height - 2 do
15+ for x = 1 to tile_width - 2 do
16+ let nx = (tile.{y, x - 1 } -. tile.{y, x + 1 }) *. deltay in
17+ let ny = (tile.{y - 1 , x} -. tile.{y + 1 , x}) *. deltax in
18+ let nz = 2. *. deltax *. deltay in
19+ let n = 127. /. sqrt ((nx *. nx) +. (ny *. ny) +. (nz *. nz)) in
20+ normals.{tile_height - 2 - y, x - 1 , 0 } < - truncate (nx *. n);
21+ normals.{tile_height - 2 - y, x - 1 , 1 } < - truncate (ny *. n);
22+ normals.{tile_height - 2 - y, x - 1 , 2 } < - truncate (nz *. n);
23+ heights.{tile_height - 2 - y, x - 1 } < - tile.{y, x}
24+ done
25+ done
26+
27+ let tile_height = 1024
28+
29+ let tile_width = 1024
30+
31+ let tile = Bigarray. (Array2. create Float32 C_layout ) tile_height tile_width
32+
33+ let () =
34+ for _ = 1 to 10 do
35+ precompute tile_height tile_width tile
36+ done
Original file line number Diff line number Diff line change 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+ dune build --profile release --root .
10+ node _build/default/bench.bc.js 400000
11+ $(MAKE ) perform COMPILER=js_of_ocaml SCRIPT=_build/default/bench.bc.js KIND=js
12+ $(MAKE ) perform COMPILER=wasm_of_ocaml SCRIPT=_build/default/bench.bc.wasm.js KIND=wasm
13+ @date -u +" %FT%TZ - $( NAME) : done"
14+
15+ perform :
16+ /usr/bin/time -f ' {"compiler": "$(COMPILER)", "time":"%E"}' node $(SCRIPT ) 2>&1 | \
17+ sh ../../utils/format_metrics.sh exec | \
18+ sh ../../utils/aggregate.sh $(KIND )
Original file line number Diff line number Diff line change 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. eprintf " %.2f@." (t' -. t)
Original file line number Diff line number Diff line change 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))
Original file line number Diff line number Diff line change 1+ (lang dune 3 .19)
You can’t perform that action at this time.
0 commit comments