trackSync static method

Duration trackSync(
  1. SyncFunction callback, {
  2. String? name,
})

Tracks the time it takes for a synchronous callback to complete.

callback: The synchronous callback to track. name: Used only in debug mode to identify the callback, if not provided, the callback's toString() will be used.

Returns the duration of the callback.

Implementation

static Duration trackSync(SyncFunction callback, {String? name}) {
  final tracker = SyncTimeTracker();
  tracker.track(callback);
  final statement = '${name ?? callback}\n -- took: ${tracker.duration.sMsUsFormatted}';
  dprint(statement);
  return tracker.duration;
}