File: opt.ml

package info (click to toggle)
ocaml 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,372 kB
  • sloc: ml: 370,196; ansic: 52,820; sh: 27,419; asm: 5,462; makefile: 3,684; python: 974; awk: 278; javascript: 273; perl: 59; fortran: 21; cs: 9
file content (51 lines) | stat: -rw-r--r-- 1,375 bytes parent folder | download | duplicates (2)
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
46
47
48
49
50
51
(** Parse command line options *)

let test_size =
  try int_of_string (Sys.getenv "OCAML_TEST_SIZE")
  with Not_found | Failure _ -> 0

let (default_avail, default_size, default_nruns) =
  if test_size >= 3 then (8, 5000, 20)
  else if test_size = 2 then (4, 5000, 20)
  else (2, 1000, 10)

let verbose = ref false
and size = ref 5000
and nruns = ref 20
and navail = ref default_avail

module type Config = sig
  val verbose : bool
  val size : int
  val nruns : int
  val navail : int
end

module Make (N : sig val pgm : string end) =
  struct
    let pgm =
      if Array.length Sys.argv > 0 then Sys.argv.(0) else N.pgm

    let () =
      let doc_def msg r = Printf.sprintf "<n> %s, default %d" msg !r in
      let open Arg in
      Arg.parse
        [
          "-v",Set verbose,"be verbose";
          "-q",Clear verbose,"be silent";
          "-s",Int (fun i -> size :=i), doc_def "size of arrays" size ;
          "-r",Int (fun i -> nruns :=i),doc_def "number of iterations" nruns ;
          "-a",Int (fun i -> navail :=i),
          doc_def "number of cores available for tests" navail ;
        ]
        (fun _ -> raise (Bad "No argument allowed"))
        (Printf.sprintf "%s: (options)*, where options are:" pgm)

    module Config = struct
      let verbose = !verbose
      let size = !size
      let nruns = !nruns
      let navail = !navail
    end

  end