testExecute function

FutureOr testExecute({
  1. String title = '',
  2. bool timer = true,
  3. required Function function,
  4. bool execute = true,
  5. dynamic isAsync = false,
})

执行测试

Implementation

FutureOr testExecute(
    {String title = '',
    bool timer = true,
    required Function function,
    bool execute = true,
    isAsync = false}) async {
  if (execute) {
    print('$title:');
    var suffix = '';
    late Stopwatch stopwatch;
    if (timer) {
      stopwatch = Stopwatch()..start();
    }
    if (isAsync) {
      await function();
    } else {
      function();
    }
    if (timer) {
      stopwatch.stop();
      suffix = ': ${stopwatch.elapsed}';
    }
    print('$title$suffix\n');
  }
}