timeSync<T> method

T timeSync<T>(
  1. String operation,
  2. T fn()
)

Time a synchronous operation.

Implementation

T timeSync<T>(String operation, T Function() fn) {
  if (!_enabled) return fn();
  final sw = Stopwatch()..start();
  try {
    final result = fn();
    sw.stop();
    record(operation, sw.elapsed, success: true);
    return result;
  } catch (e) {
    sw.stop();
    record(operation, sw.elapsed, success: false);
    rethrow;
  }
}