pocket_watch

Values

pub fn callback(
  with callback: fn(String) -> b,
  time body: fn() -> a,
) -> a

Log time taken using a provided callback.

Examples:

let print_time = fn(label, elapsed) { io.println_error(label <> " took " <> elapsed) }

{
  use <- pocket_watch.callback(print_time("test", _))

  process.sleep(1000)
} // test took 1.0s
pub fn callback_ns(
  with callback: fn(Float) -> b,
  time body: fn() -> a,
) -> a

Log time taken using a provided callback that takes Float nanoseconds as argument.

Examples:

let print_time = fn(label, elapsed) {
  io.println_error(label <> " took " <> float.to_string(elapsed /. 1_000_000.0) <> "ms")
}

{
  use <- pocket_watch.callback(print_time("test", _))

  process.sleep(1000)
} // test took 1000.0ms
pub fn simple(label: String, body: fn() -> a) -> a

Log time taken using a default callback with io.println_error.

Examples:

{
  use <- pocket_watch.simple("test")

  process.sleep(1000)
} // pocket_watch [test]: took 1.0s
pub fn summary_simple(
  label label: String,
  runs n: Int,
  warmup warmup: Int,
  time body: fn() -> a,
) -> a

Note: Be aware of side effects when using any of the summary functions. body will be called multiple times and any side effects will be triggered each time.

Shortcut to the simple function in the summary module.

Check out that function for details!

Search Document