runBenchmarks function

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

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.

Implementation

Future<void> runBenchmarks(
  Map<String, RecorderFactory> benchmarks, {
  String initialPage = defaultInitialPage,
}) 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 current 'page' value set to [initialPage] to
  // ensure the benchmark app is reloaded at the proper location.
  final String newUri = Uri(
    scheme: currentUri.scheme,
    host: currentUri.host,
    port: currentUri.port,
    path: initialPage,
  ).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);
}