benchmark function

void benchmark(
  1. String name,
  2. void callback(), {
  3. int iterations = 10,
  4. Duration duration = const Duration(seconds: 2),
})

Creates a new benchmark with the given name and callback.

A benchmark will run for a certain duration, it will execute the callback times the amount of iterations. That is one execution call, and the time it takes to execute will then be added to the elapsed time.

When the elapsed time is equal or greater than the duration it will stop and calculate the benchmark time: performanceTime = elapsedTime / whileIterationsDone.

The name will be added to the names of any surrounding groups.

If iterations is passed, it will be used as the amount of iterations this benchmark will use for execution, by default it will be 10 iterations.

If duration is passed, it will be used as the time that the benchmark has to run, it will execute the benchmark as long as the time hasn't passed, by default it will be 2 seconds.

Implementation

void benchmark(
  String name,
  void Function() callback, {
  int iterations = 10,
  Duration duration = const Duration(seconds: 2),
}) {
  _g.benchmark(name, callback, iterations: iterations, duration: duration);
}