microbenchCommand function

Future<int> microbenchCommand(
  1. List<String> args, {
  2. void log(
    1. String line
    ) = print,
})

Runs the microbench command with args and returns its exit code.

Without a command name (diff, help or run) first, args are those of run: dart run microbench runs every benchmark.

Parameters:

  • args: the command line.
  • log: receives every line of output.

Implementation

Future<int> microbenchCommand(
  List<String> args, {
  void Function(String line) log = print,
}) async {
  final command = args.isEmpty ? '' : args.first;
  if (command == 'help' || command == '--help' || command == '-h') {
    log(microbenchUsage);
    return 0;
  }
  try {
    if (command == 'diff') return _diff(args.sublist(1), log);
    return await _run(command == 'run' ? args.sublist(1) : args, log);
  } on FormatException catch (e) {
    log('microbench: ${e.message}\n\n$microbenchUsage');
    return 64;
  } on ArgumentError catch (e) {
    log('microbench: ${e.message}: ${e.invalidValue}\n\n$microbenchUsage');
    return 64;
  } on FileSystemException catch (e) {
    log('microbench: ${e.message}: ${e.path}');
    if (e.path == 'benchmark' && command != 'diff') log(firstBenchmarkHint);
    return 1;
  }
}