Skip to content

Commit 91826c5

Browse files
committed
Benchmark: bigarrays
1 parent b1fc090 commit 91826c5

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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

0 commit comments

Comments
 (0)