runBenchmarks function

Future<void> runBenchmarks(
  1. Map<String, RecorderFactory> benchmarks, {
  2. String benchmarkPath = defaultInitialPath,
})

Starts a local benchmark client to run benchmarks.

Usually used in combination with a benchmark server, which orders the client to run each benchmark in order.

When used without a server, prompts the user to select a benchmark to run next.

benchmarkPath specifies the path for the URL that will be loaded in Chrome when reloading the window for subsequent benchmark runs.

Implementation

Future<void> runBenchmarks(
  Map<String, RecorderFactory> benchmarks, {
  String benchmarkPath = defaultInitialPath,
}) async {
  // Set local benchmarks.
  _benchmarks = benchmarks;

  // Check if the benchmark server wants us to run a specific benchmark.
  final String nextBenchmark = await _client.requestNextBenchmark();

  if (nextBenchmark == LocalBenchmarkServerClient.kManualFallback) {
    _fallbackToManual(
        'The server did not tell us which benchmark to run next.');
    return;
  }

  await _runBenchmark(nextBenchmark);

  final Uri currentUri = Uri.parse(window.location.href);
  // Create a new URI with the parsed value of [benchmarkPath] to ensure the
  // benchmark app is reloaded with the proper configuration.
  final String newUri = Uri.parse(benchmarkPath)
      .replace(
        scheme: currentUri.scheme,
        host: currentUri.host,
        port: currentUri.port,
      )
      .toString();

  // Reloading the window will trigger the next benchmark to run.
  await _client.printToConsole(
    'Client preparing to reload the window to: "$newUri"',
  );
  window.location.replace(newUri);
}