benchmark_runner 2.2.0 copy "benchmark_runner: ^2.2.0" to clipboard
benchmark_runner: ^2.2.0 copied to clipboard

A library for writing inline micro-benchmarks, running sync/async benchmarks, reporting and exporting score statistics.

example/README.md

Benchmark Runner - Example #

Dart

Usage #

Include benchmark_runner as a dev_dependency in your pubspec.yaml file.

Write inline benchmarks using the functions:

  • benchmark: Creates and runs a synchronous benchmark and reports the benchmark score.
  • asyncBenchmark: Creates and runs an asynchronous benchmark.
  • group: Used to label a group of benchmarks. The callback body usually contains one or several calls to benchmark and asyncBenchmark. Benchmark groups may not be nested.
  • asyncGroup: Used to label an asynchronous group of benchmarks. The callback body usually contains one or several calls to asyncBenchmark.
  • Files must end with _benchmark.dart in order to be detected as benchmark files by benchmark_runner.

The example below shows a benchmark file containing synchronous and asynchronous benchmarks.

import 'dart:io';

import 'package:benchmark_runner/benchmark_runner.dart';

/// Returns the value [t] after waiting for [duration].
Future<T> later<T>(T t, [Duration duration = Duration.zero]) async {
sleep(duration); // Has lower overhead compared to Future.pause.
return t;
}

void main(List<String> args) async {
await asyncGroup('1: Wait for duration', () async {
  await asyncBenchmark('10ms', () async {
    await later<int>(39, Duration(milliseconds: 10));
  });

  await asyncBenchmark('5ms', () async {
    await later<String>('result', Duration(milliseconds: 5));
  }, scoreEmitter: MeanEmitter());
});

group('2: Set', () {
  benchmark('error test', () {
    throw ('Thrown in benchmark: error test.');
  });

  benchmark('construct', () {
    final set = {for (var i = 0; i < 1000; ++i) i};
  });

  throw 'Error in group';
});
}

Run a single benchmark file as an executable:

$ dart benchmark/example_async_benchmark.dart

Run several benchmark files (ending with _benchmark.dart) by calling the benchmark_runner and specifying a directory. If no directory or file name is specified, then it defaults to benchmark:

$ dart run benchmark_runner report

Features and bugs #

Please file feature requests and bugs at the issue tracker.

3
likes
160
points
235
downloads

Documentation

API reference

Publisher

verified publishersimphotonics.com

Weekly Downloads

A library for writing inline micro-benchmarks, running sync/async benchmarks, reporting and exporting score statistics.

Repository (GitHub)
View/report issues

Topics

#benchmark #async #inline #histogram #statistics

License

BSD-3-Clause (license)

Dependencies

ansi_modifier, args, exception_templates, glob, lazy_memo, path

More

Packages that depend on benchmark_runner