benchmark<R> function

BenchmarkResult<R> benchmark<R>(
  1. String name,
  2. int loops,
  3. BenchMarkFunction<R> f, {
  4. bool verbose = false,
  5. dynamic printer(
    1. Object? o
    )?,
})

Performas a benchmark of BenchMarkFunction f.

Implementation

BenchmarkResult<R> benchmark<R>(String name, int loops, BenchMarkFunction<R> f,
    {bool verbose = false, Function(Object? o)? printer}) {
  var chronometer = BenchmarkResult<R>(name)..start();
  var result = f(loops);
  chronometer.stop(operations: result.operations);
  chronometer._result = result.result;

  if (verbose) {
    if (printer != null) {
      printer(chronometer);
    } else {
      print(chronometer);
    }
  }

  return chronometer;
}