timeIt<T> method

T timeIt<T>(
  1. String label,
  2. T fn()
)

Executes fn, logs its elapsed time under label, and rethrows any exception with timing info attached.

Implementation

T timeIt<T>(String label, T Function() fn) {
  final sw = Stopwatch()..start();
  try {
    final result = fn();
    sw.stop();
    logInfo('$label: ${sw.elapsedMilliseconds}ms');
    return result;
  } catch (e) {
    sw.stop();
    logError(label);
    logError('THREW after ${sw.elapsedMilliseconds}ms : $e');
    rethrow;
  }
}