mirage / bechamel

Agnostic benchmark in OCaml (proof-of-concept)
MIT License
44 stars 15 forks source link

Feature request: provide a teardown / finalize hook for benchmarks #22

Closed craigfe closed 2 years ago

craigfe commented 3 years ago

The type of Test.make_indexed is currently:

val make_indexed : name:string -> ?fmt:fmt_indexed -> args:int list -> (int -> (unit -> 'a) Staged.t) -> t

This gives space for performing actions before a benchmark (after receiving the int), and during an individual run (after receiving the unit), but as far as I can see there's no hook into performing actions after a run. This feature could be useful for benchmarks that need to close their resources after they're done.

In my particular case, I have a test that wants to map a big chunk of memory, benchmark individual operations, then teardown that memory:

let noop_run size =
  let t = Uring.create ~queue_depth:size () in
  Staged.stage (fun () ->
      for i = 1 to size do let r = Uring.noop t i in assert r done;
      let submitted = Uring.submit t in assert (submitted = size);
      for _ = 1 to size do ignore (Uring.wait t : (int * int) option) done)
 (* Want to run [Uring.exit] somewhere, to avoid a memory leak. *)
craigfe commented 2 years ago

Resolved by #25, so closing. Thanks!