/usr/share/doc/libbenchmark-ocaml-dev/examples/loops.ml is in libbenchmark-ocaml-dev 1.3-2build1.
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 | open Benchmark
(* Test for the speed of recusion w.r.t. imperative loops to access
arrays fo floats. *)
let rec_loop (a : float array) =
let rec loop i =
if i < Array.length a then begin
a.(i) <- a.(i) +. 1.;
loop (i + 1)
end in
loop 0
let rec_loop2 (a : float array) =
let len = Array.length a in
let rec loop i =
if i < len then begin
a.(i) <- a.(i) +. 1.;
loop (i + 1)
end in
loop 0
let for_loop (a : float array) =
for i = 0 to Array.length a - 1 do
a.(i) <- a.(i) +. 1.
done
let () =
let a = Array.make 100 1. in
let res = throughputN ~repeat:5 1
[("rec", rec_loop, a);
("rec2", rec_loop2, a);
("for", for_loop, a); ] in
tabulate res
|