package bechamel

  1. Overview
  2. Docs

Module Bechamel.TestSource

Sourcetype packed =
  1. | V : ([ `Init ] -> unit -> 'a) -> packed
Sourcemodule Elt : sig ... end
Sourcetype t
Sourcetype fmt_indexed = (string -> int -> string, Format.formatter, unit, string) format4
Sourcetype fmt_grouped = (string -> string -> string, Format.formatter, unit, string) format4
Sourceval make : name:string -> (unit -> 'a) Staged.t -> t

make ~name fn is a naming benchmark measuring fn. fn can be constructed with Staged.stage:

  let write =
    Test.make ~name:"unix-write"
      (Staged.stage @@ fun () -> Unix.write Unix.stdout "Hello World!")
Sourceval make_indexed : name:string -> ?fmt:fmt_indexed -> args:int list -> (int -> (unit -> 'a) Staged.t) -> t

make_indexed ~name ~fmt ~args fn is naming benchmarks indexed by an argument (by args). Name of each benchmark is Fmt.strf fmt name arg (default to "%s:%d").

  let make_list words =
    Staged.stage @@ fun () ->
    let rec go n acc = if n = 0 then acc else go (n - 1) (n :: acc) in
    go ((words / 3) + 1) []

  let test =
    make_indexed ~name:"make_list" ~args:[ 0; 10; 100; 100 ] make_list

This kind of test is helpful to see results of the same implementation with differents arguments (indexed by the given int).

Sourceval make_grouped : name:string -> ?fmt:fmt_grouped -> t list -> t

make_grouped ~name ~fmt tests is naming benchmarks. Name of each benchmark is Fmt.strf fmt name arg (default to %s/%s).

  let f0 = Test.make ~name:"fib1" ... ;; let f1 = Test.make ~name:"fib0"
  ... ;;

  let test = Test.make_grouped ~name:"fibonacci" [ f0; f1; ] ;;

This kind of test is helpful to compare results betwen many implementations.

Sourceval name : t -> string

name t returns the name of the test.

Sourceval names : t -> string list

names t returns names of sub-tests of t (such as indexed tests or grouped tests).

Sourceval elements : t -> Elt.t list

elements t returns all measuring functions of t.

Sourceval expand : t list -> Elt.t list
OCaml

Innovation. Community. Security.