measureAsync<T> static method

Future<T> measureAsync<T>(
  1. String name,
  2. Future<T> operation()
)

Implementation

static Future<T> measureAsync<T>(
  String name,
  Future<T> Function() operation,
) async {
  final stopwatch = Stopwatch()..start();
  try {
    final result = await operation();
    stopwatch.stop();
    DKLog.i(
      '$name 耗时: ${stopwatch.elapsedMilliseconds}ms',
      tag: 'Performance',
    );
    return result;
  } catch (e) {
    stopwatch.stop();
    DKLog.e(
      '$name 失败,耗时: ${stopwatch.elapsedMilliseconds}ms',
      tag: 'Performance',
      error: e,
    );
    rethrow;
  }
}