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

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

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.
  • 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.

// ignore_for_file: unused_local_variable

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]) {
  return Future.delayed(duration, () => t);
}

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

    await asyncBenchmark('5ms', () async {
      await later<int>(27, Duration(milliseconds: 5));
    }, emitStats: false);
  });

  group('Set', () async {
    await asyncBenchmark('error test', () {
      throw ('Thrown in benchmark.');
    });

    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

Features and bugs #

Please file feature requests and bugs at the issue tracker.

2
likes
0
pub points
27%
popularity

Publisher

verified publishersimphotonics.com

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

Repository (GitHub)
View/report issues

Topics

#benchmark #async #inline #histogram #statistics

License

unknown (license)

Dependencies

ansi_modifier, benchmark_harness, exception_templates, lazy_memo

More

Packages that depend on benchmark_runner