benchmark

0.3.0

A full featured library for writing and running Dart benchmarks.

Download archive

Readme

plugin version coverage report pipeline status dependencies

benchmark

benchmark provides a standard way of writing and running benchmarks in Dart. Inspired by both benchmark_harness and test.

Writing Benchmarks.

Benchmarks are specified using the top-level benchmark() function:

import 'package:benchmark/benchmark.dart';

void main() {
  benchmark('List.generate(100k)', () {
    List.generate(100000, (i) => i);
  });
}

Benchmarks can be grouped together using the group() function. Each group's description is added to the beginning of its benchmark's descriptions:

import 'package:benchmark/benchmark.dart';

void main() {
  group('List', () {
    benchmark('.generate(100k)', () {
      List.generate(100000, (i) => i);
    });
  });

  group('Map', () {
    benchmark('.unmodifiable(other)', () {
      Map.unmodifiable({
        'value': 1
      });
    }, iterations: 100);
  });
}

Groups at the same level, with the same name, will be merged into one, allowing for different benchmark setups, without losing the overview in the output.

You can use the setUp() and tearDown() functions to share code between benchmarks. The setUp() callback will run before every benchmark in a group, and tearDown() will run after:

import 'package:benchmark/benchmark.dart';

void main() {
  List<int> list;

  setUp(() => list = List.generate(100000, (i) => i));

  tearDown(() => list = null);

  benchmark('List(100k).forEach()', () {
    list.forEach((i) {});
  });
}

You can use the setUpEach() and tearDownEach() functions to share code between iterations of benchmarks. The setUpEach() callback will run before every iteration in a benchmark, and tearDownEach() will run after:

import 'package:benchmark/benchmark.dart';

void main() {
  List<int> list;

  setUpEach(() => list = List.generate(100000, (i) => i));

  tearDownEach(() => list = null);

  benchmark('List(100k).map()', () {
    list.map((i) => '$i');
  });
}

Running benchmarks

benchmark comes with a simple executable to automatically run all your benchmarks:

pub run benchmark

See the --help flag for more information.

Changelog

0.3.0

  • Stable null safety release.

0.2.1

  • Groups with the same name on the same level will be merged together.
  • Benchmark can now be run in environments without a terminal attached, for instance in a CI/CD.

0.2.0

  • BREAKING: Removed the report() function in favour of the command line tool.
  • BREAKING: Removed both GroupEntry and BenchmarkRunner classes as parts from the library, they are not useful outside of the library.
  • Improved the command line tool, beter visual output.

0.1.0

  • Added group() function.
  • Added benchmark() function.
  • Added setUp() function.
  • Added setUpEach() function.
  • Added setUpAll() function.
  • Added tearDown() function.
  • Added tearDownEach() function.
  • Added tearDownAll() function.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add benchmark
pubspec.yaml
name: benchmark
description: A full featured library for writing and running Dart benchmarks.
version: 0.3.0
homepage: https://gitlab.com/wolfenrain/benchmark

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  meta: ^1.2.4
  args: ^2.0.0

dev_dependencies:
  test: ^1.16.5
  coverage: ^1.0.1
  pedantic: ^1.11.0

Version history

VersionPublishedArchiveSHA-256
0.1.0On demandDownload28c1b1be…081d7f
0.2.0On demandDownloadc95d517e…8d6a2f
0.2.1On demandDownloadce7dccb4…eeadc2
0.3.0Cached · Upstream SHA-256 matchedDownloadcb3eeea0…54493b

Dependencies

args "^2.0.0"

meta "^1.2.4"