measure<T> static method

Future<T> measure<T>(
  1. String name,
  2. FutureOr<T> fn()
)

Runs fn and adds the time it took as name, also when it throws. Without the middleware it only runs fn.

Implementation

static Future<T> measure<T>(String name, FutureOr<T> Function() fn) async {
  Object? timings = Zone.current[_key];
  if (timings is! _Timings) return await fn();
  Stopwatch watch = Stopwatch()..start();
  try {
    return await fn();
  } finally {
    timings.add(name, watch.elapsed, null);
  }
}