Module Jupyter_notebook.Bench

Benchmark functions

Types

type 'a t = {
  1. b_rtime : 'a;
    (*

    Real time for the process

    *)
  2. b_utime : 'a;
    (*

    User time for the process

    *)
  3. b_stime : 'a;
    (*

    System time for the process

    *)
}

The type of execution time of functions or code snippets.

'a is float or stat.

  • since 2.8.0
type stat = {
  1. bs_mean : float;
    (*

    Mean of execution time per a loop

    *)
  2. bs_std : float;
    (*

    Standard deviation of execution time per a loop

    *)
}

The type of summary results of repeated measurement of execution time.

  • since 2.8.0

Benchmark

val time : (unit -> 'a) -> 'a * float t

time f measures execution time of a function f.

  • returns

    a pair of f () and a result of benchmark.

  • since 2.8.0
val timeit : ?runs:int -> ?loops_per_run:int -> ?before_run:(unit -> unit) -> ?after_run:(unit -> unit) -> (unit -> 'a) -> stat t

timeit ?runs ?loops_per_run ?before_run ?after_run f repeatedly executes a function f, and measures the mean and the standard deviation of each execution time of f ().

for i = 1 to runs do
  before_run () ;
  (* --- start measurement of execution time of each run --- *)
  for _ = 1 to loops_per_run do
    ignore (f ()) ;
  done ;
  (* --- finish measurement --- *)
  after_run () ;
done

timeit is inspired by timeit package in Python. The parameter loops_per_run, before_run are named as number, setup respectively in Python.

  • parameter runs

    the number of running (default = 5)

  • parameter loops_per_run

    the number of loops per each run (default = 1,000,000)

  • parameter before_run

    function once called before each run.

  • parameter after_run

    function once called after each run.

  • returns

    summary of measurement.

  • since 2.8.0

Pretty printers

val pp : (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a t -> unit
  • since 2.8.0
val pp_float_t : Stdlib.Format.formatter -> float t -> unit
  • since 2.8.0
val pp_timedelta : Stdlib.Format.formatter -> float -> unit
  • since 2.8.0
val pp_stat : Stdlib.Format.formatter -> stat -> unit
  • since 2.8.0