File: try_if.ml

package info (click to toggle)
ocaml-benchmark 1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 300 kB
  • sloc: ml: 1,114; makefile: 45; perl: 12
file content (35 lines) | stat: -rw-r--r-- 654 bytes parent folder | download
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
open Bigarray

let n = 100

let a = Array1.create float64 fortran_layout n

(* Base case: no test *)
let f0 () =
  for i = 1 to n do
    let x = a.{i} in
    ignore(x)
  done;
  ignore(0.)

let f1 () =
  for i = 1 to n+1 do
    let x = try a.{i} with _ -> 0. in
    ignore(x)
  done

let f2 () =
  for i = 1 to n+1 do
    let x = if i <= n then a.{i} else 0. in
    ignore(x)
  done

open Benchmark

let () =
  let res = throughputN ~repeat:5 3 [("no test", f0, ());
                                     ("try", f1, ());
                                     ("if", f2, ())  ] in
  print_endline "Bigarray bound checking:";
  tabulate res;
  print_gc res