Skip to content

time

time<A>(fn, config): (a) => A

Defined in: Composition/tap.ts:212

Runs a function and measures its execution duration, returning the value unchanged. Supports both synchronous and asynchronous functions. If the timed function returns a Promise, duration measurement resolves asynchronously upon resolution/rejection.

A

(a) => unknown

TimeConfig

(a) => A

// Time a synchronous computation
pipe(
  data,
  tap.time(processData, { label: "sync-process" })
);

// Time an asynchronous fetch with custom metrics callback
pipe(
  data,
  tap.time(fetchData, {
    onFinish: (dur) => metrics.histogram("api.time", Duration.to.milliseconds(dur))
  })
);