package bechamel
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=e9d26f9201fd98f860e9b3afad7a5d520f04ae9c95bea070f5d0ac2c26abff4d
sha512=eac5f8aa192d66ba70a28ce44bdbf6a849ff1a82a8efbaab87067e2ee06c00bcc04e6f16923948857eec41cb171e3915d1e4cb751be7cf95d4521d5dbe4dd858
doc/bechamel/Bechamel/Test/index.html
Module Bechamel.TestSource
and ('a, 'v, 'k) kind = private | Uniq : ('a, unit, Uniq.t) kind| Multiple : ('a, int, Multiple.t) kind
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!")val make_with_resource :
name:string ->
('a, 'f, 'g) kind ->
allocate:(unit -> 'a) ->
free:('a -> unit) ->
('a -> 'b) Staged.t ->
tmake_with_resource ~name k ~allocate ~free fn is a naming benchmark measuring fn with a pre-allocated resource 'v (given by allocate). It permits to measure fn which requires a resource allocated before the benchmark. Then, this resource can be free-ed via the given free function.
Depending on the k given, the resource can be allocated only one time or per run:
uniq, the resource is allocated one ime before the benchmark and used byfnfor all runs. Then, it is free-ed at the end of the benchmark.multiple, the resource is allocated multiple times (depending on how many times we want to runfn) at the beginning of the benchmark andfnis executed with a structurally different resource perrun. Then, these resources are free-ed at the end of the benchmark.
NOTE: the multiple case can ask a huge allocation (for instance, it can call 3000 times allocate). Be aware that such usage, depending on what you allocate, can lead an Out_of_memory exception.
val make_indexed :
name:string ->
?fmt:fmt_indexed ->
args:int list ->
(int -> (unit -> 'a) Staged.t) ->
tmake_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_listThis kind of test is helpful to see results of the same implementation with differents arguments (indexed by the given int).
val make_indexed_with_resource :
name:string ->
?fmt:fmt_indexed ->
args:int list ->
('a, 'f, 'g) kind ->
allocate:(int -> 'a) ->
free:('a -> unit) ->
(int -> ('a -> 'b) Staged.t) ->
tmake_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 between many implementations.
names t returns names of sub-tests of t (such as indexed tests or grouped tests).