benchmark function

BenchmarkResult benchmark(
  1. String name,
  2. void body(), {
  3. int iterations = 10000,
})

Run a benchmark: execute body iterations times and measure the total.

Implementation

BenchmarkResult benchmark(
  String name,
  void Function() body, {
  int iterations = 10000,
}) {
  final sw = Stopwatch()..start();
  for (var i = 0; i < iterations; i++) {
    body();
  }
  sw.stop();
  return BenchmarkResult(name, iterations, sw.elapsedMicroseconds);
}