/usr/share/doc/libbenchmark-ocaml-dev/examples/iter.ml is in libbenchmark-ocaml-dev 1.3-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | open Bigarray
let n = 1_000
(* Bigarrays *)
type vec = (float, float64_elt, c_layout) Array1.t
let a = Array1.create float64 c_layout n
let () = Array1.fill a 1.
let ba f (x: vec) =
for i = 0 to n - 1 do f x.{i} done
let ba_unsafe f (x: vec) =
for i = 0 to n - 1 do f (Array1.unsafe_get x i) done
(* Arrays *)
let b = Array.make n 1.
let arr f (x: float array) =
for i = 0 to n-1 do f x.(i) done
let arr_unsafe f (x: float array) =
for i = 0 to n-1 do f (Array.unsafe_get x i) done
(* Lists *)
let c = Array.to_list b
open Benchmark
let () =
(* Simulate a simple side effect *)
let z = ref 0. in
let f x = z := x in
let res = throughputN ~repeat:3 3
[("ba", (fun () -> ba f a), ());
("ba_unsafe", (fun () -> ba_unsafe f a), ());
("arr", (fun () -> arr f b), ());
("arr_unsafe", (fun () -> arr_unsafe f b), ());
("list", (fun () -> List.iter f c), ())
] in
print_endline "Iterating a function with a simple side effect:";
tabulate res
|